Author: Grid.Qian
Date: 2009-03-19 23:01:56 -0400 (Thu, 19 Mar 2009)
New Revision: 14277
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.classpath
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.project
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.settings/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.settings/org.eclipse.jdt.core.prefs
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/META-INF/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/META-INF/MANIFEST.MF
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/build.properties
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/layoutH.gif
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/layoutV.gif
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/process.gif
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.properties
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.xml
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/MultiPageEditorPlugin.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/InnerJpdlEditor.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditor.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditorContributor.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPage.properties
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPageMessages.java
Log:
GPD290: add a multipage editor for gpd
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.classpath
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.classpath
(rev 0)
+++ trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.classpath 2009-03-20 03:01:56
UTC (rev 14277)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.project
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.project
(rev 0)
+++ trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.project 2009-03-20 03:01:56
UTC (rev 14277)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.flow.jpdl4.multipage</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.settings/org.eclipse.jdt.core.prefs
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/.settings/org.eclipse.jdt.core.prefs 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,7 @@
+#Wed Mar 11 13:52:50 CST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/META-INF/MANIFEST.MF
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/META-INF/MANIFEST.MF 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.jboss.tools.flow.jpdl4.multipageeditor;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.jboss.tools.flow.jpdl4.multipage.MultiPageEditorPlugin
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.jface.text,
+ org.eclipse.core.resources,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.ide,
+ org.jboss.tools.flow.jpdl4;bundle-version="1.0.0",
+ org.eclipse.wst.sse.ui;bundle-version="1.1.3",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="3.4.1",
+ org.jboss.tools.flow.common;bundle-version="1.0.0",
+ org.eclipse.gef;bundle-version="3.4.1"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/build.properties
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/build.properties
(rev 0)
+++ trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/build.properties 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/layoutH.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/layoutH.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/layoutV.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/layoutV.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/process.gif
===================================================================
(Binary files differ)
Property changes on:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/icons/process.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.properties
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.properties
(rev 0)
+++ trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.properties 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,2 @@
+pluginName=Jpdl4 Multipage Editor Plug-in
+providerName=JBoss, a Division of Red Hat
\ No newline at end of file
Added: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.xml
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.xml
(rev 0)
+++ trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/plugin.xml 2009-03-20 03:01:56
UTC (rev 14277)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+
class="org.jboss.tools.flow.jpdl4.multipage.editors.MultiPageEditor"
+
contributorClass="org.jboss.tools.flow.jpdl4.multipage.editors.MultiPageEditorContributor"
+ extensions="xml"
+ icon="icons/process.gif"
+ id="org.jboss.tools.flow.jpdl4.multipage.editors.MultiPageEditor"
+ name="jBPM Graphical Process Designer">
+ </editor>
+ </extension>
+
+</plugin>
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/MultiPageEditorPlugin.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/MultiPageEditorPlugin.java
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/MultiPageEditorPlugin.java 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.flow.jpdl4.multipage;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ *
+ * @author Grid Qian
+ */
+public class MultiPageEditorPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID =
"org.jboss.tools.flow.jpdl4.multipageeditor";
+
+ // The shared instance
+ private static MultiPageEditorPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public MultiPageEditorPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static MultiPageEditorPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/InnerJpdlEditor.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/InnerJpdlEditor.java
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/InnerJpdlEditor.java 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.flow.jpdl4.multipage.editors;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.jboss.tools.flow.jpdl4.editor.JpdlEditor;
+
+/**
+ * the jpdl editor is only for the multipage editor. It extends jpdl editor and
+ * do some small changes for adapting to the multipage editor.
+ *
+ * @author Grid Qian
+ */
+public class InnerJpdlEditor extends JpdlEditor {
+
+ public String JpdlEditorID = "org.jboss.tools.flow.jpdl4.editor";
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ IEditorPart activeEditor = getSite().getPage().getActiveEditor();
+ if (activeEditor instanceof MultiPageEditor) {
+ MultiPageEditor mulEditor = (MultiPageEditor) activeEditor;
+
+ if (mulEditor.getActiveInnerEditor() == this)
+ updateActions(super.getSelectionActions());
+ }
+ super.selectionChanged(part, selection);
+ }
+
+ public void writeModel(OutputStream os) throws IOException {
+ super.writeModel(os);
+ }
+ public void setModel(Object model) {
+ super.setModel(model);
+ }
+
+ public String getContributorId() {
+ return JpdlEditorID;
+ }
+}
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditor.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditor.java
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditor.java 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.flow.jpdl4.multipage.editors;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.MultiPageEditorPart;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.flow.common.wrapper.Wrapper;
+import org.jboss.tools.flow.jpdl4.editor.JpdlDeserializer;
+import org.jboss.tools.flow.jpdl4.multipage.message.MultiPageMessages;
+
+/**
+ * @author Grid Qian
+ */
+public class MultiPageEditor extends MultiPageEditorPart implements
+ IResourceChangeListener{
+
+ private InnerJpdlEditor jpdlEditor;
+
+ private StructuredTextEditor xmlEditor;
+
+ /**
+ * Creates a multi-page editor.
+ */
+ public MultiPageEditor() {
+ super();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ }
+
+ public void init(IEditorSite site, IEditorInput input)throws PartInitException{
+ super.init(site, input);
+ }
+
+ void createJpdl4EditorPage() {
+ try {
+ jpdlEditor = new InnerJpdlEditor();
+ int pageNum = addPage((IEditorPart) jpdlEditor, getEditorInput());
+ super.setPageText(pageNum, MultiPageMessages.Jpdl_Page_Name);
+ } catch (PartInitException e) {
+ ErrorDialog.openError(getSite().getShell(),
+ "Error creating Jpdl editor", null, e.getStatus());
+ }
+ }
+
+ void createXmlEditorPage() {
+ try {
+ xmlEditor = new StructuredTextEditor();
+ int pageNum = addPage((IEditorPart) xmlEditor, getEditorInput());
+ super.setPageText(pageNum, MultiPageMessages.Xml_Page_Name);
+ } catch (PartInitException e) {
+ ErrorDialog.openError(getSite().getShell(),
+ "Error creating xml editor", null, e.getStatus());
+ }
+ }
+
+ protected void createPages() {
+ createJpdl4EditorPage();
+ createXmlEditorPage();
+ super.setPartName(jpdlEditor.getPartName());
+ }
+
+ public void pageChange(int newPageIndex) {
+ if(this.isDirty()){
+ if(this.getActiveEditor() instanceof StructuredTextEditor){
+ doPageChangeFromJpdlToXml();
+ } else {
+ doPageChangeFromXmlToJpdl();
+ }
+ }
+ super.pageChange(newPageIndex);
+ }
+
+ private void doPageChangeFromXmlToJpdl() {
+ String xmlText =
xmlEditor.getDocumentProvider().getDocument(xmlEditor.getEditorInput()).get();
+ ByteArrayInputStream in = new ByteArrayInputStream(xmlText.getBytes());
+ Wrapper model = new JpdlDeserializer().deserialize(in);
+ if(model != null && model.getElement() != null) {
+ jpdlEditor.setModel(model);
+ ((GraphicalViewer) jpdlEditor.getAdapter(GraphicalViewer.class)).setContents(model);
+ } else {
+ System.out.println("Ha!");
+ }
+
+ try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private void doPageChangeFromJpdlToXml() {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ jpdlEditor.writeModel(out);
+ xmlEditor.getDocumentProvider().getDocument(xmlEditor.getEditorInput()).set(out.toString());
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * return the active editor of the multipage editor
+ */
+ public IEditorPart getActiveInnerEditor(){
+ return getActiveEditor();
+ }
+
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ if(this.getActiveEditor() instanceof StructuredTextEditor){
+ doPageChangeFromXmlToJpdl();
+ }
+ jpdlEditor.doSave(monitor);
+ xmlEditor.doSave(monitor);
+ }
+
+ @Override
+ public void doSaveAs() {
+ if(this.getActiveEditor() instanceof StructuredTextEditor){
+ doPageChangeFromXmlToJpdl();
+ }
+ jpdlEditor.doSaveAs();
+ xmlEditor.doSave(null);
+
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return jpdlEditor.isSaveAsAllowed();
+ }
+
+ public void resourceChanged(IResourceChangeEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditorContributor.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditorContributor.java
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/editors/MultiPageEditorContributor.java 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.flow.jpdl4.multipage.editors;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.AlignmentRetargetAction;
+import org.eclipse.gef.ui.actions.DeleteRetargetAction;
+import org.eclipse.gef.ui.actions.GEFActionConstants;
+import org.eclipse.gef.ui.actions.RedoRetargetAction;
+import org.eclipse.gef.ui.actions.UndoRetargetAction;
+import org.eclipse.gef.ui.actions.ZoomComboContributionItem;
+import org.eclipse.gef.ui.actions.ZoomInRetargetAction;
+import org.eclipse.gef.ui.actions.ZoomOutRetargetAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.RetargetAction;
+import org.eclipse.ui.ide.IDEActionFactory;
+import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.flow.common.Activator;
+import org.jboss.tools.flow.common.action.HorizontalAutoLayoutAction;
+import org.jboss.tools.flow.common.action.VerticalAutoLayoutAction;
+import org.jboss.tools.flow.common.editor.DropDownMenuWithDefaultAction;
+
+/**
+ * The contributor is for build actions for two editors of the multipage editor
+ *
+ * @author Grid Qian
+ */
+public class MultiPageEditorContributor extends
+ MultiPageEditorActionBarContributor {
+
+ // zoom combo button for jpdl editor
+ private ZoomComboContributionItem zoomCombo = null;
+ // a map to contain the id of a retarget action to the retarget action
+ // instance
+ private Map<String, RetargetAction> actionMap = new HashMap<String,
RetargetAction>();
+
+ private static final String[] WORKBENCH_ACTION_IDS = {
+ ActionFactory.PRINT.getId(), ActionFactory.DELETE.getId(),
+ ActionFactory.SAVE.getId(), ActionFactory.UNDO.getId(),
+ ActionFactory.REDO.getId(), ActionFactory.CUT.getId(),
+ ActionFactory.COPY.getId(), ActionFactory.PASTE.getId(),
+ ActionFactory.SELECT_ALL.getId(), ActionFactory.FIND.getId(),
+ IDEActionFactory.BOOKMARK.getId() };
+ private static final String[] TEXTEDITOR_ACTION_IDS = {
+ ITextEditorActionConstants.PRINT,
+ ITextEditorActionConstants.DELETE, ITextEditorActionConstants.SAVE,
+ ITextEditorActionConstants.UNDO, ITextEditorActionConstants.REDO,
+ ITextEditorActionConstants.CUT, ITextEditorActionConstants.COPY,
+ ITextEditorActionConstants.PASTE,
+ ITextEditorActionConstants.SELECT_ALL,
+ ITextEditorActionConstants.FIND, IDEActionFactory.BOOKMARK.getId() };
+
+ /*
+ * Creates a multi-page contributor.
+ */
+ public MultiPageEditorContributor() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.ui.part.EditorActionBarContributor#init(org.eclipse.ui.
+ * IActionBars)
+ */
+ public void init(IActionBars bars) {
+ buildActions(bars);
+ contributeJpdlEditorToolBarAction(bars.getToolBarManager());
+ super.init(bars);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActivePage
+ * (org.eclipse.ui.IEditorPart)
+ */
+ public void setActivePage(IEditorPart activeEditor) {
+ IActionBars actionBars = getActionBars();
+ if (actionBars == null)
+ return;
+ actionBars.clearGlobalActionHandlers();
+ if (activeEditor instanceof InnerJpdlEditor) {
+ addJpdlEditorActions((InnerJpdlEditor) activeEditor, actionBars);
+ } else if (activeEditor instanceof StructuredTextEditor) {
+ addXmlEditorActions((StructuredTextEditor) activeEditor, actionBars);
+ }
+ actionBars.updateActionBars();
+ }
+
+ /*
+ * set the global actions for jpdl editor
+ */
+ private void addJpdlEditorActions(InnerJpdlEditor activeEditor,
+ IActionBars actionBars) {
+ // get the registry of actions from jpdl editor
+ ActionRegistry registry = (ActionRegistry) activeEditor
+ .getAdapter(ActionRegistry.class);
+
+ // set jpdl global action to workbench global action
+ for (int i = 0; i < WORKBENCH_ACTION_IDS.length; i++) {
+ actionBars.setGlobalActionHandler(WORKBENCH_ACTION_IDS[i], registry
+ .getAction(WORKBENCH_ACTION_IDS[i]));
+ }
+
+ // set the retarget action of jpdl editor to jpdl golbal action
+ String[] keys = actionMap.keySet().toArray(
+ new String[actionMap.keySet().size()]);
+ for (int i = 0; i < keys.length; i++) {
+ actionBars.setGlobalActionHandler(keys[i], registry
+ .getAction(keys[i]));
+ }
+
+ // make zoomCombo visible
+ zoomCombo.setVisible(true);
+ actionBars.getToolBarManager().update(true);
+
+ }
+
+ /*
+ * set the global actions for xml editor
+ */
+ private void addXmlEditorActions(StructuredTextEditor activeEditor,
+ IActionBars actionBars) {
+ // set the global actions of jpdl editor are unable.
+ String[] keys = actionMap.keySet().toArray(
+ new String[actionMap.keySet().size()]);
+ for (int i = 0; i < keys.length; i++) {
+ actionBars.setGlobalActionHandler(keys[i], null);
+ }
+
+ //set the global actions to xml editor global action
+ for (int i = 0; i < WORKBENCH_ACTION_IDS.length; i++) {
+ actionBars.setGlobalActionHandler(WORKBENCH_ACTION_IDS[i],
+ activeEditor.getAction(TEXTEDITOR_ACTION_IDS[i]));
+ }
+ zoomCombo.setVisible(false);
+ }
+
+ /*
+ * create retarget actions for jpdl editor
+ */
+ private void buildActions(IActionBars actionBars) {
+ addRetargetAction(new UndoRetargetAction());
+ addRetargetAction(new RedoRetargetAction());
+ addRetargetAction(new DeleteRetargetAction());
+ addRetargetAction(new ZoomInRetargetAction());
+ addRetargetAction(new ZoomOutRetargetAction());
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE));
+ addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM));
+ addRetargetAction(new RetargetAction(
+ GEFActionConstants.TOGGLE_GRID_VISIBILITY, "Grid"));
+ RetargetAction verticalAutoLayoutAction = new RetargetAction(
+ VerticalAutoLayoutAction.ID, null);
+ verticalAutoLayoutAction.setImageDescriptor(ImageDescriptor
+ .createFromURL(Activator.getDefault().getBundle().getEntry(
+ "icons/layoutV.gif")));
+ addRetargetAction(verticalAutoLayoutAction);
+ RetargetAction horizontalAutoLayoutAction = new RetargetAction(
+ HorizontalAutoLayoutAction.ID, null);
+ horizontalAutoLayoutAction.setImageDescriptor(ImageDescriptor
+ .createFromURL(Activator.getDefault().getBundle().getEntry(
+ "icons/layoutH.gif")));
+ addRetargetAction(horizontalAutoLayoutAction);
+ }
+
+ /*
+ * add the retargetaction to the map
+ */
+ protected void addRetargetAction(RetargetAction action) {
+ actionMap.put(action.getId(), action);
+ getPage().addPartListener(action);
+ }
+
+ /*
+ * add the retarget actions to jpdl tool bar
+ */
+ public void contributeJpdlEditorToolBarAction(IToolBarManager toolBarManager) {
+ toolBarManager.add(actionMap.get(ActionFactory.UNDO.getId()));
+ toolBarManager.add(actionMap.get(ActionFactory.REDO.getId()));
+ toolBarManager.add(new Separator());
+ zoomCombo = new ZoomComboContributionItem(getPage());
+ toolBarManager.add(zoomCombo);
+ toolBarManager.add(new Separator());
+
+ DropDownMenuWithDefaultAction alignMenu = new DropDownMenuWithDefaultAction(
+ actionMap.get(GEFActionConstants.ALIGN_LEFT));
+ alignMenu.add(actionMap.get(GEFActionConstants.ALIGN_LEFT));
+ alignMenu.add(actionMap.get(GEFActionConstants.ALIGN_CENTER));
+ alignMenu.add(actionMap.get(GEFActionConstants.ALIGN_RIGHT));
+ alignMenu.add(new Separator());
+ alignMenu.add(actionMap.get(GEFActionConstants.ALIGN_TOP));
+ alignMenu.add(actionMap.get(GEFActionConstants.ALIGN_MIDDLE));
+ alignMenu.add(actionMap.get(GEFActionConstants.ALIGN_BOTTOM));
+ toolBarManager.add(alignMenu);
+
+ toolBarManager.add(new Separator());
+ toolBarManager.add(actionMap
+ .get(GEFActionConstants.TOGGLE_GRID_VISIBILITY));
+
+ toolBarManager.add(new Separator());
+ toolBarManager.add(actionMap.get(VerticalAutoLayoutAction.ID));
+ toolBarManager.add(actionMap.get(HorizontalAutoLayoutAction.ID));
+ }
+
+ public void dispose() {
+ String[] keys = actionMap.keySet().toArray(
+ new String[actionMap.keySet().size()]);
+ for (int i = 0; i < keys.length; i++) {
+ RetargetAction action = (RetargetAction) actionMap.get(keys[i]);
+ getPage().removePartListener(action);
+ action.dispose();
+ }
+ actionMap.clear();
+ actionMap = null;
+
+ zoomCombo.dispose();
+ }
+}
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPage.properties
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPage.properties
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPage.properties 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,2 @@
+Jpdl_Page_Name=Diagram
+Xml_Page_Name=Source
\ No newline at end of file
Added:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPageMessages.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPageMessages.java
(rev 0)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4.multipage/src/org/jboss/tools/flow/jpdl4/multipage/message/MultiPageMessages.java 2009-03-20
03:01:56 UTC (rev 14277)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.flow.jpdl4.multipage.message;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Grid Qian
+ */
+public class MultiPageMessages {
+
+ private static final String BUNDLE_NAME =
"org.jboss.tools.flow.jpdl4.multipage.message.MultiPage"; //$NON-NLS-1$
+
+ public static String Jpdl_Page_Name;
+ public static String Xml_Page_Name;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, MultiPageMessages.class);
+ }
+}
\ No newline at end of file