org.simantics.image.ui;bundle-version="1.0.0",
org.simantics.export.core;bundle-version="1.0.0",
org.slf4j.api,
- org.simantics.graphfile.ontology
+ org.simantics.graphfile.ontology,
+ org.eclipse.e4.core.services
Export-Package: org.simantics.modeling.ui,
org.simantics.modeling.ui.actions,
org.simantics.modeling.ui.chart.property,
Bundle-Activator: org.simantics.modeling.ui.Activator
Bundle-ActivationPolicy: lazy
Bundle-Vendor: VTT Technical Research Centre of Finland
-Import-Package: org.simantics.views
+Import-Package: org.osgi.service.event,
+ org.simantics.views
*******************************************************************************/
package org.simantics.modeling.ui.diagramEditor.handlers.e4;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.e4.core.contexts.Active;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MToolItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
import org.simantics.g2d.diagram.DiagramHints;
import org.simantics.g2d.diagram.IDiagram;
/**
* @author Tuukka Lehtonen
*/
+@SuppressWarnings("restriction")
public class ToggleFocusabilityHandler {
- @CanExecute
- public boolean canExecute(@Active MPart part) {
- if (!(part.getObject() instanceof CompatibilityEditor))
- return false;
- CompatibilityEditor editor = (CompatibilityEditor) part.getObject();
- if (!(editor.getPart() instanceof DiagramEditor))
- return false;
- return true;
- }
-
+ private static final String HANDLED_ITEM_ID = "fi.vtt.apros.ui.diagram.handledtoolitem.enableimageeditability";
+
+ @Inject
+ private EModelService modelService;
+
+ private void updateStateForPart(MPart part) {
+ IWorkbenchPart wbPart = tryGetWorkbenchPart(part);
+ if (wbPart != null) {
+ MWindow win = modelService.getTopLevelWindowFor(part);
+ MToolItem item = (MToolItem) modelService.find(HANDLED_ITEM_ID, win);
+ ILayersEditor le = getLayers(wbPart);
+ if (item != null && le != null) {
+ setToolItemState(item, le.getIgnoreFocusSettings());
+ }
+ }
+ }
+
+ // tracks the active part
+ @Inject
+ @Optional
+ public void receiveActivePart(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
+ updateStateForPart(activePart);
+ }
+
+ @CanExecute
+ public boolean canExecute(@Active MPart part) {
+ return tryGetWorkbenchPart(part) instanceof DiagramEditor;
+ }
+
@Execute
public void execute(@Optional MToolItem toolItem) {
ILayersEditor le = getLayers();
if (le != null) {
- boolean b = le.getIgnoreFocusSettings();
- le.setIgnoreFocusSettings( !b );
-
+ boolean newValue = !le.getIgnoreFocusSettings();
+ le.setIgnoreFocusSettings( newValue );
if (toolItem != null) {
- toolItem.setSelected(!b);
- toolItem.setTooltip((!b ? "Deny" : "Allow") + " Focusing and Editing of Images");
+ setToolItemState(toolItem, newValue);
}
}
}
+ private void setToolItemState(MToolItem item, boolean ignoreFocusSettings) {
+ item.setSelected(ignoreFocusSettings);
+ item.setTooltip((ignoreFocusSettings ? "Deny" : "Allow") + " Focusing and Editing of Images");
+ }
+
protected ILayersEditor getLayers() {
DiagramEditor editor = getEditor();
if (editor == null)
return getLayers(editor);
}
- protected ILayersEditor getLayers(DiagramEditor editor) {
+ protected ILayersEditor getLayers(IAdaptable editor) {
// The diagram might not be available since the diagram editor loads it asynchronously.
IDiagram diagram = (IDiagram) editor.getAdapter(IDiagram.class);
if (diagram == null)
return null;
}
+ private IWorkbenchPart tryGetWorkbenchPart(MPart part) {
+ if (part == null)
+ return null;
+ Object obj = part.getObject();
+ if (obj instanceof CompatibilityEditor) {
+ CompatibilityEditor editor = (CompatibilityEditor) obj;
+ return editor.getPart();
+ } else if (obj instanceof IWorkbenchPart) {
+ return (IWorkbenchPart) obj;
+ }
+ return null;
+ }
+
}