28 |
28 |
import java.awt.event.ComponentEvent;
|
29 |
29 |
import java.awt.event.InputEvent;
|
30 |
30 |
import java.awt.event.MouseEvent;
|
|
31 |
import java.util.List;
|
31 |
32 |
import java.util.function.Predicate;
|
32 |
33 |
import javax.swing.Action;
|
33 |
34 |
|
... | ... | |
36 |
37 |
import org.apache.commons.lang3.StringUtils;
|
37 |
38 |
|
38 |
39 |
import org.cresques.cts.IProjection;
|
|
40 |
import org.gvsig.expressionevaluator.Expression;
|
39 |
41 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
|
40 |
42 |
import org.gvsig.expressionevaluator.GeometryExpressionUtils;
|
41 |
43 |
import org.slf4j.Logger;
|
... | ... | |
45 |
47 |
import org.gvsig.featureform.swing.JFeaturesForm;
|
46 |
48 |
import org.gvsig.fmap.dal.DataStoreProviderFactory;
|
47 |
49 |
import org.gvsig.fmap.dal.exception.DataException;
|
|
50 |
import org.gvsig.fmap.dal.feature.FacadeOfAFeature;
|
|
51 |
import org.gvsig.fmap.dal.feature.Feature;
|
48 |
52 |
import org.gvsig.fmap.dal.feature.FeatureQuery;
|
49 |
53 |
import org.gvsig.fmap.dal.feature.FeatureSelection;
|
50 |
54 |
import org.gvsig.fmap.dal.feature.FeatureSet;
|
... | ... | |
86 |
90 |
*/
|
87 |
91 |
@SuppressWarnings("UseSpecificCatch")
|
88 |
92 |
public class AttributeEditorPointListener
|
89 |
|
extends AbstractPointListener
|
|
93 |
extends AbstractToolListener
|
90 |
94 |
implements RectangleListener
|
91 |
95 |
{
|
92 |
96 |
|
... | ... | |
127 |
131 |
|
128 |
132 |
}
|
129 |
133 |
|
130 |
|
@Override
|
131 |
|
public void point(PointEvent e) throws BehaviorException {
|
132 |
|
MouseEvent mouseEvent = e.getEvent();
|
133 |
|
if (((mouseEvent.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK
|
134 |
|
| InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.META_DOWN_MASK)) != 0)
|
135 |
|
|| !SwingUtilities.isLeftMouseButton(mouseEvent)) {
|
136 |
|
return;
|
137 |
|
}
|
|
134 |
// @Override
|
|
135 |
// public void point(PointEvent e) throws BehaviorException {
|
|
136 |
// MouseEvent mouseEvent = e.getEvent();
|
|
137 |
// if (((mouseEvent.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK
|
|
138 |
// | InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK | InputEvent.META_DOWN_MASK)) != 0)
|
|
139 |
// || !SwingUtilities.isLeftMouseButton(mouseEvent)) {
|
|
140 |
// return;
|
|
141 |
// }
|
|
142 |
// String layerName = "";
|
|
143 |
// I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
144 |
// try {
|
|
145 |
// FLyrVect layer = getLayer();
|
|
146 |
// if (layer == null) {
|
|
147 |
// String msg = i18nManager.getTranslation("There_is_no_one_and_only_one_active_layer");
|
|
148 |
// ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
|
|
149 |
// i18nManager.getTranslation("attribute_editor"), JOptionPane.INFORMATION_MESSAGE);
|
|
150 |
// return;
|
|
151 |
// }
|
|
152 |
// layerName = layer.getName();
|
|
153 |
// ViewPort vp = this.mapControl.getViewPort();
|
|
154 |
// Point point = vp.convertToMapPoint(e.getPoint());
|
|
155 |
// double tolerance = vp.toMapDistance(layer.getDefaultTolerance());
|
|
156 |
// FeatureQuery query = queryByPoint(point, tolerance);
|
|
157 |
// showOrUpdateForm(layer, query);
|
|
158 |
// } catch (Exception ex) {
|
|
159 |
// LOGGER.warn("Can't show attribute information from point on the layer " + layerName, ex);
|
|
160 |
// String msg =
|
|
161 |
// i18nManager.getTranslation("Cant_show_attribute_information_for_layer_%1_on_point",
|
|
162 |
// new String[] { layerName });
|
|
163 |
// ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
|
|
164 |
// i18nManager.getTranslation("attribute_editor"), JOptionPane.WARNING_MESSAGE);
|
|
165 |
// }
|
|
166 |
// }
|
|
167 |
|
|
168 |
public void showOrUpdateForm() {
|
138 |
169 |
String layerName = "";
|
139 |
170 |
I18nManager i18nManager = ToolsLocator.getI18nManager();
|
140 |
171 |
try {
|
141 |
172 |
FLyrVect layer = getLayer();
|
142 |
173 |
if (layer == null) {
|
143 |
|
String msg = i18nManager.getTranslation("There_is_no_one_and_only_one_active_layer");
|
144 |
|
ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
|
145 |
|
i18nManager.getTranslation("attribute_editor"), JOptionPane.INFORMATION_MESSAGE);
|
146 |
174 |
return;
|
147 |
175 |
}
|
148 |
176 |
layerName = layer.getName();
|
149 |
|
ViewPort vp = this.mapControl.getViewPort();
|
150 |
|
Point point = vp.convertToMapPoint(e.getPoint());
|
151 |
|
double tolerance = vp.toMapDistance(layer.getDefaultTolerance());
|
152 |
|
FeatureQuery query = queryByPoint(point, tolerance);
|
|
177 |
FeatureQuery query;
|
|
178 |
FeatureStore store = layer.getFeatureStore();
|
|
179 |
if(store.isFeatureSelectionEmpty()){
|
|
180 |
return;
|
|
181 |
}
|
|
182 |
FeatureSelection selection = store.getFeatureSelectionQuietly();
|
|
183 |
Expression filter = selection.makeFilter(100);
|
|
184 |
|
|
185 |
if(filter == null){
|
|
186 |
String msg =
|
|
187 |
i18nManager.getTranslation("_Unable_to_get_filter_for_XlayernameX_layer_selection",
|
|
188 |
new String[] { layerName });
|
|
189 |
ToolsSwingLocator.getThreadSafeDialogsManager().message(msg, JOptionPane.WARNING_MESSAGE);
|
|
190 |
return;
|
|
191 |
}
|
|
192 |
if(selection.size()>100){
|
|
193 |
String msg =
|
|
194 |
i18nManager.getTranslation("_Too_many_items_selected_Only_the_first_100_will_be_displayed",
|
|
195 |
new String[] { layerName });
|
|
196 |
ToolsSwingLocator.getThreadSafeDialogsManager().message(msg, JOptionPane.WARNING_MESSAGE);
|
|
197 |
|
|
198 |
}
|
|
199 |
query = store.createFeatureQuery(filter);
|
|
200 |
|
153 |
201 |
showOrUpdateForm(layer, query);
|
154 |
202 |
} catch (Exception ex) {
|
155 |
|
LOGGER.warn("Can't show attribute information from point on the layer " + layerName, ex);
|
|
203 |
LOGGER.warn("Can't show attribute information from selection on the layer " + layerName, ex);
|
156 |
204 |
String msg =
|
157 |
|
i18nManager.getTranslation("Cant_show_attribute_information_for_layer_%1_on_point",
|
|
205 |
i18nManager.getTranslation("_Cant_show_attribute_information_for_layer_XlayernameX_on_selection",
|
158 |
206 |
new String[] { layerName });
|
159 |
207 |
ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(msg,
|
160 |
208 |
i18nManager.getTranslation("attribute_editor"), JOptionPane.WARNING_MESSAGE);
|
161 |
209 |
}
|
|
210 |
|
162 |
211 |
}
|
163 |
212 |
|
164 |
213 |
private void showOrUpdateForm(FLyrVect layer, FeatureQuery query) {
|
... | ... | |
178 |
227 |
}
|
179 |
228 |
I18nManager i18n = ToolsLocator.getI18nManager();
|
180 |
229 |
try {
|
|
230 |
synchronized (featureStore) {
|
|
231 |
|
181 |
232 |
if( StringUtils.isBlank(storeName) ) {
|
182 |
233 |
storeName = featureStore.getLabel();
|
183 |
234 |
}
|
184 |
|
try {
|
185 |
|
synchronized (featureStore) {
|
186 |
|
FeatureSet featSet = featureStore.getFeatureSet(query);
|
187 |
|
if( featSet.isEmpty() ) {
|
188 |
|
return;
|
189 |
|
}
|
190 |
|
FeatureSelection selection = (FeatureSelection) featureStore.getSelection();
|
191 |
|
selection.deselectAll();
|
192 |
|
selection.select(featSet);
|
193 |
|
}
|
194 |
|
} catch (DataException ex) {
|
195 |
|
LOGGER.warn("Can't query layer " + storeName+", query: "+query, ex);
|
196 |
|
return;
|
197 |
|
}
|
198 |
235 |
if (this.form == null) {
|
199 |
236 |
this.form = getForm(featureStore, query);
|
200 |
|
this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
|
|
237 |
// this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
|
201 |
238 |
} else if( this.form.getFeatureStore()!=featureStore ) {
|
202 |
239 |
// Dimension size = this.form.asJComponent().getPreferredSize();
|
203 |
240 |
disposeForm();
|
204 |
241 |
this.form = getForm(featureStore, query);
|
205 |
242 |
// this.form.asJComponent().setPreferredSize(size);
|
206 |
|
this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
|
|
243 |
// this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
|
|
244 |
} else {
|
|
245 |
this.form.setQuery(query);
|
207 |
246 |
}
|
208 |
|
this.form.setQuery(query);
|
|
247 |
List<Feature> values = this.form.getFormset().getValues();
|
|
248 |
FeatureSelection selection = (FeatureSelection) featureStore.getSelection();
|
|
249 |
selection.deselectAll();
|
|
250 |
FeatureSelection selectionTmp = featureStore.createFeatureSelection();
|
|
251 |
for (Feature fof : values) {
|
|
252 |
selectionTmp.select(fof);
|
|
253 |
}
|
|
254 |
selection.select(selectionTmp);
|
|
255 |
// try {
|
|
256 |
// synchronized (featureStore) {
|
|
257 |
// FeatureSet featSet = featureStore.getFeatureSet(query);
|
|
258 |
// if( featSet.isEmpty() ) {
|
|
259 |
// return;
|
|
260 |
// }
|
|
261 |
// FeatureSelection selection = (FeatureSelection) featureStore.getSelection();
|
|
262 |
// selection.deselectAll();
|
|
263 |
// selection.select(featSet);
|
|
264 |
// }
|
|
265 |
// } catch (DataException ex) {
|
|
266 |
// LOGGER.warn("Can't query layer " + storeName+", query: "+query, ex);
|
|
267 |
// return;
|
|
268 |
// }
|
|
269 |
|
|
270 |
this.form.showForm(makeTitle("attribute_editor", storeName, featureStore.getName()), MODE.TOOL);
|
|
271 |
}
|
209 |
272 |
} catch (Exception ex) {
|
210 |
273 |
LOGGER.warn("Can't show attribute information from point on the layer " + storeName, ex);
|
211 |
274 |
String msg =
|