]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/ui/LinkTimeHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / LinkTimeHandler.java
index ce08eddcb531c6b8ea85a5646776781a43f81fbd..1f04f7056b6ef2967a27e1d30409a6578cbc51c5 100644 (file)
@@ -1,92 +1,92 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.charts.ui;\r
-\r
-import java.util.Map;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.Command;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.commands.IHandler;\r
-import org.eclipse.core.commands.State;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IEditorReference;\r
-import org.eclipse.ui.IWorkbenchPage;\r
-import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.IWorkbenchWindow;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.commands.ICommandService;\r
-import org.eclipse.ui.commands.IElementUpdater;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.eclipse.ui.menus.UIElement;\r
-import org.simantics.charts.editor.TimeSeriesEditor;\r
-\r
-public class LinkTimeHandler extends AbstractHandler implements IHandler, IElementUpdater {\r
-\r
-    public static final String COMMAND_ID = "org.simantics.charts.linktime";\r
-    public static final String STATE_ID = "org.simantics.charts.linktime.state";\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
-        Command command = service.getCommand( COMMAND_ID );\r
-        State state = command.getState( STATE_ID );\r
-        if (state != null) {\r
-            ChartLinkData oldData = (ChartLinkData) state.getValue();\r
-            if (oldData == null) {\r
-                TimeSeriesEditor editor = getEditor( event );\r
-                ChartLinkData currentData = new ChartLinkData();\r
-                if (editor != null) {\r
-                    editor.getFromEnd(currentData);\r
-                }\r
-                state.setValue( currentData );\r
-            } else {\r
-                state.setValue(null);\r
-            }\r
-        }\r
-\r
-        service.refreshElements(COMMAND_ID, null);\r
-        return null;\r
-    }\r
-\r
-    /**\r
-     * Get active editor or first one\r
-     * @return\r
-     */\r
-    TimeSeriesEditor getEditor(ExecutionEvent event) {\r
-        IWorkbenchPart ap = HandlerUtil.getActivePart(event);\r
-        if ( ap instanceof TimeSeriesEditor ) return (TimeSeriesEditor) ap;\r
-\r
-        IWorkbenchWindow win = HandlerUtil.getActiveWorkbenchWindow(event);\r
-        if (win==null) return null;\r
-        for (IWorkbenchPage page : win.getPages()) {\r
-            for (IEditorReference ref : page.getEditorReferences()) {\r
-                if (ref.getId().equals(TimeSeriesEditor.ID)) {\r
-                    IEditorPart part = ref.getEditor(false);\r
-                    return (TimeSeriesEditor) part;\r
-                }\r
-            }\r
-        }\r
-\r
-        return null;\r
-    }\r
-\r
-    @Override\r
-    public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {\r
-        ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
-        Command command = service.getCommand( COMMAND_ID );\r
-        State state = command.getState( STATE_ID );\r
-        element.setChecked( state != null && state.getValue()!=null );\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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.charts.ui;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.State;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.menus.UIElement;
+import org.simantics.charts.editor.TimeSeriesEditor;
+
+public class LinkTimeHandler extends AbstractHandler implements IHandler, IElementUpdater {
+
+    public static final String COMMAND_ID = "org.simantics.charts.linktime";
+    public static final String STATE_ID = "org.simantics.charts.linktime.state";
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
+        Command command = service.getCommand( COMMAND_ID );
+        State state = command.getState( STATE_ID );
+        if (state != null) {
+            ChartLinkData oldData = (ChartLinkData) state.getValue();
+            if (oldData == null) {
+                TimeSeriesEditor editor = getEditor( event );
+                ChartLinkData currentData = new ChartLinkData();
+                if (editor != null) {
+                    editor.getFromEnd(currentData);
+                }
+                state.setValue( currentData );
+            } else {
+                state.setValue(null);
+            }
+        }
+
+        service.refreshElements(COMMAND_ID, null);
+        return null;
+    }
+
+    /**
+     * Get active editor or first one
+     * @return
+     */
+    TimeSeriesEditor getEditor(ExecutionEvent event) {
+        IWorkbenchPart ap = HandlerUtil.getActivePart(event);
+        if ( ap instanceof TimeSeriesEditor ) return (TimeSeriesEditor) ap;
+
+        IWorkbenchWindow win = HandlerUtil.getActiveWorkbenchWindow(event);
+        if (win==null) return null;
+        for (IWorkbenchPage page : win.getPages()) {
+            for (IEditorReference ref : page.getEditorReferences()) {
+                if (ref.getId().equals(TimeSeriesEditor.ID)) {
+                    IEditorPart part = ref.getEditor(false);
+                    return (TimeSeriesEditor) part;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
+        ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
+        Command command = service.getCommand( COMMAND_ID );
+        State state = command.getState( STATE_ID );
+        element.setChecked( state != null && state.getValue()!=null );
+    }
+
+}