|
| 1 | +package com.vividsolutions.jump.workbench.ui.plugin; |
| 2 | + |
| 3 | +import com.vividsolutions.jump.util.Blackboard; |
| 4 | +import com.vividsolutions.jump.workbench.WorkbenchContext; |
| 5 | +import com.vividsolutions.jump.workbench.model.Layer; |
| 6 | +import com.vividsolutions.jump.workbench.plugin.*; |
| 7 | +import com.vividsolutions.jump.workbench.ui.*; |
| 8 | +import com.vividsolutions.jump.workbench.ui.images.IconLoader; |
| 9 | +import org.openjump.core.ui.plugin.view.ViewOptionsPlugIn; |
| 10 | + |
| 11 | +import javax.swing.*; |
| 12 | +import java.awt.event.KeyEvent; |
| 13 | +import java.util.Iterator; |
| 14 | + |
| 15 | +public class UniqueFeatureInfoPlugIn extends AbstractPlugIn { |
| 16 | + |
| 17 | + private static EnableCheck checker = null; |
| 18 | + |
| 19 | + public UniqueFeatureInfoPlugIn() { |
| 20 | + this.setShortcutKeys(KeyEvent.VK_I); |
| 21 | + this.setShortcutModifiers(KeyEvent.ALT_MASK); |
| 22 | + } |
| 23 | + |
| 24 | + public static final ImageIcon ICON = IconLoader.icon("information_16x16.png"); |
| 25 | + |
| 26 | + public static EnableCheck createEnableCheck( |
| 27 | + WorkbenchContext workbenchContext) { |
| 28 | + if (checker == null) { |
| 29 | + EnableCheckFactory checkFactory = EnableCheckFactory.getInstance(workbenchContext); |
| 30 | + checker = new MultiEnableCheck() |
| 31 | + .add(checkFactory.createWindowWithSelectionManagerMustBeActiveCheck()) |
| 32 | + .add(checkFactory.createWindowWithLayerManagerMustBeActiveCheck()) |
| 33 | + .add( |
| 34 | + checkFactory |
| 35 | + .createWindowWithAssociatedTaskFrameMustBeActiveCheck()) |
| 36 | + .add(checkFactory.createAtLeastNItemsMustBeSelectedCheck(1)); |
| 37 | + } |
| 38 | + return checker; |
| 39 | + } |
| 40 | + |
| 41 | + public void initialize(PlugInContext context) throws Exception { |
| 42 | + super.initialize(context); |
| 43 | + } |
| 44 | + |
| 45 | + public boolean execute(PlugInContext context) throws Exception { |
| 46 | + reportNothingToUndoYet(context); |
| 47 | + // Deactivate synchronization |
| 48 | + //Don't pass in TaskFrame as LayerManagerProxy, because the TaskFrame may |
| 49 | + //be closed and thus the LayerManagerProxy may return null. [Jon Aquino] |
| 50 | + TaskFrame taskFrame = ((TaskFrameProxy) context.getActiveInternalFrame()).getTaskFrame(); |
| 51 | + InfoFrame infoFrame = taskFrame.getInfoFrame(); |
| 52 | + SelectionManager selectionManager = |
| 53 | + ((SelectionManagerProxy) context.getActiveInternalFrame()).getSelectionManager(); |
| 54 | + infoFrame.getModel().clear(); |
| 55 | + |
| 56 | + // TODO should be nice to extend FeatureInfoPlugIn to non-layer layerables |
| 57 | + for (Iterator<Layer> i = context.getLayerManager().iterator(Layer.class); i.hasNext(); ) { |
| 58 | + Layer layer = i.next(); |
| 59 | + |
| 60 | + if (selectionManager.getFeaturesWithSelectedItems(layer).isEmpty()) { |
| 61 | + continue; |
| 62 | + } |
| 63 | + //infoFrame.getModel().remove(layer); |
| 64 | + infoFrame.getModel().add(layer, selectionManager.getFeaturesWithSelectedItems(layer)); |
| 65 | + } |
| 66 | + infoFrame.surface(); |
| 67 | + |
| 68 | + return true; |
| 69 | + } |
| 70 | +} |
0 commit comments