1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.actions.e4;
14 import javax.inject.Named;
16 import org.eclipse.e4.core.di.annotations.CanExecute;
17 import org.eclipse.e4.core.di.annotations.Execute;
18 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19 import org.eclipse.e4.ui.services.IServiceConstants;
20 import org.eclipse.ui.IEditorPart;
21 import org.eclipse.ui.IWorkbenchPart;
22 import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
23 import org.simantics.db.Resource;
24 import org.simantics.modeling.ui.diagram.PageSettingsDialog;
25 import org.simantics.modeling.ui.diagramEditor.DiagramEditor;
26 import org.simantics.ui.workbench.IResourceEditorInput;
27 import org.simantics.utils.ui.workbench.WorkbenchUtils;
31 * A Handler that shows PageSettings Dialog for DiagramViewer
33 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
35 public class PageSettingsHandler {
38 public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditor) {
39 // TODO: Fix this when we get rid of CompatibilityEditors
40 IEditorPart activeEditor = null;
41 if (mActiveEditor != null && mActiveEditor.getObject() instanceof CompatibilityEditor) {
42 CompatibilityEditor compatEditor = (CompatibilityEditor) mActiveEditor.getObject();
43 activeEditor = compatEditor.getEditor();
45 // TODO: This is not good practice with E4 but an OK fallback for now
46 // activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
48 if (activeEditor == null)
51 if (activeEditor instanceof DiagramEditor) {
52 DiagramEditor editor = (DiagramEditor) activeEditor;
53 IResourceEditorInput input = (IResourceEditorInput)editor.getEditorInput();
54 Resource diagramResource = input.getResource();
55 if (diagramResource != null)
62 public void execute(){
63 IWorkbenchPart ap = WorkbenchUtils.getActiveEditor();
64 if (ap instanceof DiagramEditor) {
65 DiagramEditor editor = (DiagramEditor) ap;
66 IResourceEditorInput input = (IResourceEditorInput)editor.getEditorInput();
67 Resource diagramResource = input.getResource();
68 if (diagramResource == null)
71 PageSettingsDialog dialog = new PageSettingsDialog(diagramResource, ap.getSite().getShell());
72 if (dialog.open() == PageSettingsDialog.OK) {
73 dialog.applySettings();