X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2Fe4%2FPageSettingsHandler.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2Fe4%2FPageSettingsHandler.java;h=999762d06aa9ee18f4ee4bee1ecfb6a96077aea9;hp=bf1c8a63533c22e13c6c5a1f5fc082785cb15dc6;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/PageSettingsHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/PageSettingsHandler.java index bf1c8a635..999762d06 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/PageSettingsHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/e4/PageSettingsHandler.java @@ -1,78 +1,78 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling.ui.actions.e4; - -import javax.inject.Named; - -import org.eclipse.e4.core.di.annotations.CanExecute; -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor; -import org.simantics.db.Resource; -import org.simantics.modeling.ui.diagram.PageSettingsDialog; -import org.simantics.modeling.ui.diagramEditor.DiagramEditor; -import org.simantics.ui.workbench.IResourceEditorInput; -import org.simantics.utils.ui.workbench.WorkbenchUtils; - - -/** - * A Handler that shows PageSettings Dialog for DiagramViewer - * - * @author Marko Luukkainen - */ -public class PageSettingsHandler { - - @CanExecute - public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditor) { - // TODO: Fix this when we get rid of CompatibilityEditors - IEditorPart activeEditor = null; - if (mActiveEditor != null && mActiveEditor.getObject() instanceof CompatibilityEditor) { - CompatibilityEditor compatEditor = (CompatibilityEditor) mActiveEditor.getObject(); - activeEditor = compatEditor.getEditor(); - } else { - // TODO: This is not good practice with E4 but an OK fallback for now -// activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); - } - if (activeEditor == null) - return false; - - if (activeEditor instanceof DiagramEditor) { - DiagramEditor editor = (DiagramEditor) activeEditor; - IResourceEditorInput input = (IResourceEditorInput)editor.getEditorInput(); - Resource diagramResource = input.getResource(); - if (diagramResource != null) - return true; - } - return false; - } - - @Execute - public void execute(){ - IWorkbenchPart ap = WorkbenchUtils.getActiveEditor(); - if (ap instanceof DiagramEditor) { - DiagramEditor editor = (DiagramEditor) ap; - IResourceEditorInput input = (IResourceEditorInput)editor.getEditorInput(); - Resource diagramResource = input.getResource(); - if (diagramResource == null) - return; - - PageSettingsDialog dialog = new PageSettingsDialog(diagramResource, ap.getSite().getShell()); - if (dialog.open() == PageSettingsDialog.OK) { - dialog.applySettings(); - } - } - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.actions.e4; + +import javax.inject.Named; + +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor; +import org.simantics.db.Resource; +import org.simantics.modeling.ui.diagram.PageSettingsDialog; +import org.simantics.modeling.ui.diagramEditor.DiagramEditor; +import org.simantics.ui.workbench.IResourceEditorInput; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + + +/** + * A Handler that shows PageSettings Dialog for DiagramViewer + * + * @author Marko Luukkainen + */ +public class PageSettingsHandler { + + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditor) { + // TODO: Fix this when we get rid of CompatibilityEditors + IEditorPart activeEditor = null; + if (mActiveEditor != null && mActiveEditor.getObject() instanceof CompatibilityEditor) { + CompatibilityEditor compatEditor = (CompatibilityEditor) mActiveEditor.getObject(); + activeEditor = compatEditor.getEditor(); + } else { + // TODO: This is not good practice with E4 but an OK fallback for now +// activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + } + if (activeEditor == null) + return false; + + if (activeEditor instanceof DiagramEditor) { + DiagramEditor editor = (DiagramEditor) activeEditor; + IResourceEditorInput input = (IResourceEditorInput)editor.getEditorInput(); + Resource diagramResource = input.getResource(); + if (diagramResource != null) + return true; + } + return false; + } + + @Execute + public void execute(){ + IWorkbenchPart ap = WorkbenchUtils.getActiveEditor(); + if (ap instanceof DiagramEditor) { + DiagramEditor editor = (DiagramEditor) ap; + IResourceEditorInput input = (IResourceEditorInput)editor.getEditorInput(); + Resource diagramResource = input.getResource(); + if (diagramResource == null) + return; + + PageSettingsDialog dialog = new PageSettingsDialog(diagramResource, ap.getSite().getShell()); + if (dialog.open() == PageSettingsDialog.OK) { + dialog.applySettings(); + } + } + } + +}