diff options
author | cdumoulin | 2011-04-05 15:39:01 +0000 |
---|---|---|
committer | cdumoulin | 2011-04-05 15:39:01 +0000 |
commit | 27925048d0dc96e5de7b9156d1c1bb51a3ee4fb0 (patch) | |
tree | 889f8c11c44aab0031a624ea3e9644d57e1f7d30 /examples | |
parent | fdad00710503588856cb422821eff9388a7e27d1 (diff) | |
download | org.eclipse.papyrus-27925048d0dc96e5de7b9156d1c1bb51a3ee4fb0.tar.gz org.eclipse.papyrus-27925048d0dc96e5de7b9156d1c1bb51a3ee4fb0.tar.xz org.eclipse.papyrus-27925048d0dc96e5de7b9156d1c1bb51a3ee4fb0.zip |
ASSIGNED - bug 341927: [refactoring] Move extraplugins/core.example/* --> examples/core/*
https://bugs.eclipse.org/bugs/show_bug.cgi?id=341927
Diffstat (limited to 'examples')
40 files changed, 2922 insertions, 0 deletions
diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.classpath b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.classpath new file mode 100644 index 00000000000..2d1a4302f04 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.classpath @@ -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>
diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.project b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.project new file mode 100644 index 00000000000..a165d6f55aa --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.example.core.lifecycleevents</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>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/META-INF/MANIFEST.MF b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..2e3974acac3 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.example.core.lifecycleevents;singleton:=true +Bundle-Version: 0.8.0.qualifier +Bundle-Activator: org.eclipse.papyrus.example.core.lifecycleevents.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.papyrus.core;bundle-version="0.7.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-Vendor: %providerName diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/build.properties b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/build.properties new file mode 100644 index 00000000000..6f20375d6c7 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/build.properties @@ -0,0 +1,5 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.properties b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.properties new file mode 100644 index 00000000000..d0701f4b9f7 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.properties @@ -0,0 +1,12 @@ +#################################################################################
+# Copyright (c) 2008 CEA LIST.
+# 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:
+# Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+##################################################################################
+pluginName=Papyrus Editor Life Cycle Example
+providerName=Cedric Dumoulin
diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.xml b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.xml new file mode 100644 index 00000000000..14ac9e2043e --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.core.service">
+ <service
+ classname="org.eclipse.papyrus.example.core.lifecycleevents.LifeCycleEventsMonitorService"
+ priority="1"
+ startKind="startup"
+ useClassTypeAsKey="true">
+ </service>
+ </extension>
+
+</plugin>
diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/Activator.java b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/Activator.java new file mode 100644 index 00000000000..e39549ce693 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/Activator.java @@ -0,0 +1,50 @@ +package org.eclipse.papyrus.example.core.lifecycleevents;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.example.lifecycleevents";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (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 Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/LifeCycleEventsMonitorService.java b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/LifeCycleEventsMonitorService.java new file mode 100644 index 00000000000..5959b6831ec --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/LifeCycleEventsMonitorService.java @@ -0,0 +1,142 @@ +/**
+ *
+ */
+package org.eclipse.papyrus.example.core.lifecycleevents;
+
+import org.eclipse.papyrus.core.lifecycleevents.DoSaveEvent;
+import org.eclipse.papyrus.core.lifecycleevents.ILifeCycleEventsProvider;
+import org.eclipse.papyrus.core.lifecycleevents.ISaveEventListener;
+import org.eclipse.papyrus.core.lifecycleevents.LifeCycleEventsProvider;
+import org.eclipse.papyrus.core.services.IService;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.services.ServicesRegistry;
+
+
+/**
+ * A simple example of a class monitoring the life cycle events from the mlti editor.
+ * This class is registered as a Papyrus service.
+ * It then registered itself to the {@link LifeCycleEventsProvider}.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class LifeCycleEventsMonitorService implements IService {
+
+ protected ServicesRegistry servicesRegistry;
+ /**
+ * The object firing event about the Editor lifecycle.
+ */
+ protected ILifeCycleEventsProvider eventProvider;
+
+ /**
+ * Listener on aboutToSave events.
+ */
+ protected ISaveEventListener aboutToSaveListener = new ISaveEventListener() {
+
+ public void doSaveAs(DoSaveEvent event) {
+ System.out.println("event received: aboutToSaveAs");
+ }
+
+ public void doSave(DoSaveEvent event) {
+ System.out.println("event received: aboutToSave");
+ }
+ };
+
+ /**
+ * Listener on doSave events.
+ */
+ protected ISaveEventListener saveListener= new ISaveEventListener() {
+
+ public void doSaveAs(DoSaveEvent event) {
+ System.out.println("event received: doSaveAs");
+ }
+
+ public void doSave(DoSaveEvent event) {
+ System.out.println("event received: doSave");
+ }
+ };
+
+ /**
+ * Listener on postSave events.
+ */
+ protected ISaveEventListener postSaveListener= new ISaveEventListener() {
+
+ public void doSaveAs(DoSaveEvent event) {
+ System.out.println("event received: postSaveAs");
+ }
+
+ public void doSave(DoSaveEvent event) {
+ System.out.println("event received: postSave");
+ }
+ };
+
+ /**
+ * Constructor.
+ * This constructor is called by the ServiceRegistry when this service is created. The
+ * parameter is provided by the ServiceRegistry itself.
+ *
+ * @param servicesRegistry
+ */
+ public LifeCycleEventsMonitorService() {
+ System.out.println("LifeCycleEventsMonitorService created");
+ }
+
+ /**
+ * @see org.eclipse.papyrus.core.services.IService#disposeService()
+ *
+ */
+ public void disposeService() {
+ deactivate();
+ System.out.println("LifeCycleEventsMonitorService disposed");
+
+ }
+
+ /**
+ * Initialize the service.
+ * @see org.eclipse.papyrus.core.services.IService#init(org.eclipse.papyrus.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ */
+ public void init(ServicesRegistry servicesRegistry) {
+ this.servicesRegistry = servicesRegistry;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.core.services.IService#startService()
+ *
+ */
+ public void startService() {
+ System.out.println("LifeCycleEventsMonitorService started");
+ activate();
+ }
+
+ /**
+ * Activate listeners.
+ */
+ private void activate() {
+ try {
+ eventProvider = servicesRegistry.getService(ILifeCycleEventsProvider.class);
+ eventProvider.addAboutToDoSaveListener(aboutToSaveListener);
+ eventProvider.addDoSaveListener(saveListener);
+ eventProvider.addPostDoSaveListener(postSaveListener);
+ } catch (ServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+
+ /**
+ * Deactivate listeners
+ */
+ private void deactivate() {
+ eventProvider.removeAboutToDoSaveListener(aboutToSaveListener);
+ eventProvider.removeDoSaveListener(saveListener);
+ eventProvider.removePostDoSaveListener(postSaveListener);
+
+ }
+
+
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.classpath b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.classpath new file mode 100644 index 00000000000..2d1a4302f04 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.classpath @@ -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>
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.project b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.project new file mode 100644 index 00000000000..b58a111b857 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.example.core.sashwindows.fulleditor</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>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/META-INF/MANIFEST.MF b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..497204bc1c3 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.example.core.sashwindows.fulleditor;singleton:=true +Bundle-Version: 0.8.0.qualifier +Bundle-Activator: org.eclipse.papyrus.example.core.sashwindows.fulleditor.Activator +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.eclipse.papyrus.sasheditor;bundle-version="0.7.0", + org.eclipse.emf.ecore.xmi;bundle-version="2.5.0", + org.eclipse.papyrus.sasheditor.di;bundle-version="0.7.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: %providerName diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/build.properties b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/build.properties new file mode 100644 index 00000000000..4b8162ab8b2 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/build.properties @@ -0,0 +1,6 @@ +source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/MsgTab.gif b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/MsgTab.gif Binary files differnew file mode 100644 index 00000000000..34fb3c9d8cb --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/MsgTab.gif diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/TextEditor.gif b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/TextEditor.gif Binary files differnew file mode 100644 index 00000000000..34fb3c9d8cb --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/TextEditor.gif diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/sample.gif b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/sample.gif Binary files differnew file mode 100644 index 00000000000..34fb3c9d8cb --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/sample.gif diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.properties b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.properties new file mode 100644 index 00000000000..bc7f204d90b --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.properties @@ -0,0 +1,12 @@ +#################################################################################
+# Copyright (c) 2008 CEA LIST.
+# 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:
+# Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+##################################################################################
+pluginName=Papyrus sashwindows full editor example
+providerName=Cedric Dumoulin
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.xml b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.xml new file mode 100644 index 00000000000..c019e9ef449 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.xml @@ -0,0 +1,135 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="Sash Windows Full Editor"
+ extensions="fullEditor"
+ icon="icons/sample.gif"
+ contributorClass="org.eclipse.papyrus.example.core.sashwindows.fulleditor.editor.MultiTextEditorContributor"
+ class="org.eclipse.papyrus.example.core.sashwindows.fulleditor.editor.MultiTextEditor"
+ id="org.eclipse.papyrus.example.sashwindows.FullEditor">
+ </editor>
+ <editor
+ class="org.eclipse.papyrus.example.core.sashwindows.fulleditor.editor.DiMultiTextEditor"
+ contributorClass="org.eclipse.papyrus.example.core.sashwindows.fulleditor.editor.MultiTextEditorContributor"
+ extensions="fullEditor"
+ icon="icons/sample.gif"
+ id="org.eclipse.papyrus.example.sashwindows.DiFullEditor"
+ name="Sash Windows Full Editor (Di ContentProvider)">
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ id="org.eclipse.papyrus.example.sashwindows"
+ name="Sash Windows Examples">
+ </category>
+ <wizard
+ name="Sash Windows Full Editor"
+ icon="icons/sample.gif"
+ category="org.eclipse.papyrus.example.sashwindows"
+ class="org.eclipse.papyrus.example.core.sashwindows.fulleditor.wizards.MultiTextNewWizard"
+ id="org.eclipse.papyrus.example.sashwindows.wizards.FullEditor">
+ </wizard>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="menu:org.eclipse.ui.main.menu?after=navigate">
+ <menu
+ id="org.eclipse.example.multitext.ui.menu"
+ label="Sash Windows Full Editor">
+ <menu
+ id="org.eclipse.example.multitext.ui.menu.create"
+ label="Create Tab">
+ <command
+ commandId="org.eclipse.example.multitext.ui.command.createTestEditor"
+ icon="icons/TextEditor.gif"
+ label="Create New Text Editor"
+ style="push">
+ </command>
+ <command
+ commandId="org.eclipse.example.multitext.ui.command.createMsgControl"
+ icon="icons/MsgTab.gif"
+ label="Create Msg Tab"
+ style="push">
+ </command>
+ </menu>
+ </menu>
+ </menuContribution>
+ <menuContribution
+ locationURI="toolbar:org.eclipse.ui.main.toolbar">
+ <toolbar
+ id="org.eclipse.example.multitext.ui.toolbar">
+ <command
+ commandId="org.eclipse.example.multitext.ui.command.createTestEditor"
+ icon="icons/TextEditor.gif"
+ style="push">
+ </command>
+ <command
+ commandId="org.eclipse.example.multitext.ui.command.createMsgControl"
+ icon="icons/MsgTab.gif"
+ style="push">
+ </command>
+ </toolbar>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.example.multitext.ui.command.createTestEditor"
+ name="Create New Text Editor">
+ </command>
+ <command
+ id="org.eclipse.example.multitext.ui.command.createMsgControl"
+ name="Create Msg Tab">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.example.core.sashwindows.fulleditor.texteditor.CreateTextEditorCommandHandler"
+ commandId="org.eclipse.example.multitext.ui.command.createTestEditor">
+ <activeWhen>
+ <or>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.example.sashwindows.FullEditor">
+ </equals>
+ </with>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.example.sashwindows.DiFullEditor">
+ </equals>
+ </with>
+ </or>
+ </activeWhen>
+ </handler>
+ <handler
+ class="org.eclipse.papyrus.example.core.sashwindows.fulleditor.msgpage.CreateMessageCommandHandler"
+ commandId="org.eclipse.example.multitext.ui.command.createMsgControl">
+ <activeWhen>
+ <or>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.example.sashwindows.FullEditor">
+ </equals>
+ </with>
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.example.sashwindows.DiFullEditor">
+ </equals>
+ </with>
+ </or>
+ </activeWhen>
+ </handler>
+ </extension>
+
+</plugin>
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/Activator.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/Activator.java new file mode 100644 index 00000000000..76285bf61eb --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/Activator.java @@ -0,0 +1,77 @@ +/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST & LIFL
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.core.sashwindows.fulleditor;
+
+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
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.example.multitext.editor";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (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 Activator 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);
+ }
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/DiMultiTextEditor.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/DiMultiTextEditor.java new file mode 100644 index 00000000000..bd672bf9468 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/DiMultiTextEditor.java @@ -0,0 +1,331 @@ +/***************************************************************************** + * Copyright (c) 2009 CEA LIST & LIFL + * + * + * 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: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.example.core.sashwindows.fulleditor.editor; + + +import java.io.IOException; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.eclipse.papyrus.example.core.sashwindows.fulleditor.texteditor.TextEditorPartModel; +import org.eclipse.papyrus.sasheditor.contentprovider.IContentChangedListener; +import org.eclipse.papyrus.sasheditor.contentprovider.IPageModel; +import org.eclipse.papyrus.sasheditor.contentprovider.ISashWindowsContentProvider; +import org.eclipse.papyrus.sasheditor.contentprovider.di.DiSashModelMngr; +import org.eclipse.papyrus.sasheditor.contentprovider.di.IPageModelFactory; +import org.eclipse.papyrus.sasheditor.editor.AbstractMultiPageSashEditor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.ide.IDE; + + +/** + * An example showing how to create a multi-page editor using sash windows. + * This example start with one page, and provide actions to create new pages. + * It can be used with the full sashWindow system (extends AbstractMultiPageSashEditor) or + * with the original Eclipse MultiPageEditor (extends MultiPageEditor). + * This editor use the EMF Di implementation of the ContentProvider. + * To use one or the other, change the extended class. + */ +public class DiMultiTextEditor extends /* MultiPageEditor */AbstractMultiPageSashEditor { + + /** SashModelMngr to add pages */ + protected DiSashModelMngr sashModelMngr; + + /** Resource mngr to load and save model */ + protected ResourceMngr resourceMngr; + + /** + * A listener on model change events. + */ + IContentChangedListener contentChangedListener = new IContentChangedListener() { + + /** + * Called when the content is changed. RefreshTabs. + */ + public void contentChanged(ContentEvent event) { + System.out.println("contentChanged()"); + markDirty(); + refreshTabs(); + } + }; + + /** + * The dirty flag. + */ + protected boolean isDirty = false; + + /** + * Listener on PROP_DIRTY event. Register the change. + */ + private IPropertyListener dirtyPropertyListener = new IPropertyListener() { + + public void propertyChanged(Object source, int propId) { + if(propId == PROP_DIRTY) + isDirty = true; + } + }; + + /** + * Creates a multi-page editor example. + */ + public DiMultiTextEditor() { + super(); + // ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + // Listen on dirty event. + addPropertyListener(dirtyPropertyListener); + } + + /** + * Mark the editor as dirty, and fire appropriate event. + */ + protected void markDirty() { + isDirty = true; + firePropertyChange(PROP_DIRTY); + } + + /** + * Create and initialize the pageProvider. + */ + protected ISashWindowsContentProvider createPageProvider() { + IPageModelFactory pageFactory = new SimplePageModelFactory(); + + // sashModelMngr = new DiSashModelMngr(pageFactory, resourceMngr.getDiResource() ); + sashModelMngr = new DiSashModelMngr(pageFactory); + + ISashWindowsContentProvider pageProvider = sashModelMngr.getISashWindowsContentProvider(); + + // Adding requested pages + pageProvider.addPage(new TextEditorPartModel()); + // Listen on contentProvider changes + sashModelMngr.getSashModelContentChangedProvider().addListener(contentChangedListener); + + return pageProvider; + } + + /** + * The <code>MultiPageEditorPart</code> implementation of this <code>IWorkbenchPart</code> method disposes all nested editors. + * Subclasses may extend. + */ + public void dispose() { + // ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + sashModelMngr.getSashModelContentChangedProvider().removeListener(contentChangedListener); + super.dispose(); + } + + /** + * Saves the multi-page editor's document. + */ + public void doSave(IProgressMonitor monitor) { + + IEditorPart editor = getActiveEditor(); + if(editor != null) { + editor.doSave(monitor); + // Reset dirty flag. + isDirty = false; + } + + // try { + // resourceMngr.saveResource(monitor); + // } catch (IOException e) { + // e.printStackTrace(); + // } + } + + /** + * Saves the multi-page editor's document as another file. + * Also updates the text for page 0's tab, and updates this multi-page editor's input + * to correspond to the nested editor's. + */ + public void doSaveAs() { + IEditorPart editor = getActiveEditor(); + if(editor != null) { + editor.doSaveAs(); + // setPageText(0, editor.getTitle()); + setInput(editor.getEditorInput()); + + // Reset dirty flag. + isDirty = false; + } + } + + /* + * (non-Javadoc) + * Method declared on IEditorPart + */ + public void gotoMarker(IMarker marker) { + // setActivePage(0); + IDE.gotoMarker(getActiveEditor(), marker); + } + + /** + * The <code>MultiPageEditorExample</code> implementation of this method + * checks that the input is an instance of <code>IFileEditorInput</code>. + */ + public void init(IEditorSite site, IEditorInput editorInput) + throws PartInitException { + if(!(editorInput instanceof IFileEditorInput)) + throw new PartInitException("Invalid Input: Must be IFileEditorInput"); + super.init(site, editorInput); + + // Load model + // IFile file = ((IFileEditorInput) editorInput).getFile(); + // resourceMngr = new ResourceMngr(); + // resourceMngr.loadResource(file); + } + + /* + * (non-Javadoc) + * Method declared on IEditorPart. + */ + public boolean isSaveAsAllowed() { + return true; + } + + @Override + public boolean isDirty() { + return isDirty; + } + + /** + * Simple implementation of the factory. + * This factory return the object as is. + * + * @author dumoulin + */ + public class SimplePageModelFactory implements IPageModelFactory { + + public IPageModel createIPageModel(Object pageIdentifier) { + return (IPageModel)pageIdentifier; + } + + } + + /** + * A class managing a Resource. + * + * @author cedric dumoulin + */ + public class ResourceMngr { + + private static final String DI_FILE_EXTENSION = "di"; + + private ResourceSet resourceSet; + + private Resource diResource; + + + /** + * Constructor. + */ + public ResourceMngr() { + createResourceSet(); + } + + /** + * Return the resource used for DI model. + * + * @return + */ + public Resource getDiResource() { + return diResource; + } + + /** + * Create the resourceSet. + */ + protected void createResourceSet() { + + if(resourceSet != null) + return; + + // Create di resource + resourceSet = new ResourceSetImpl(); + + // Register the default resource factory -- only needed for stand-alone! + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( + Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); + + } + + /** + * Load resource using name provided in file. + * + * @param file + */ + public void loadResource(IFile file) { + // Extract file name, without extension + IPath fullPath = file.getFullPath().removeFileExtension(); + + IPath filePath; + filePath = fullPath.addFileExtension(DI_FILE_EXTENSION); + + URI uri = URI.createPlatformResourceURI(filePath.toString(), true); + try { + diResource = resourceSet.getResource(uri, true); + } catch (Exception e) { + // diResource = resourceSet.createResource(uri); + e.printStackTrace(); + } + + } + + /** + * Load resource using name provided in file. + * + * @param file + */ + public void createResource(IFile file) { + // Extract file name, without extension + IPath fullPath = file.getFullPath().removeFileExtension(); + + IPath filePath; + filePath = fullPath.addFileExtension(DI_FILE_EXTENSION); + + URI uri = URI.createPlatformResourceURI(filePath.toString(), true); + diResource = resourceSet.createResource(uri); + + } + + /** + * Save Resource associated to this manager. + * + * @throws IOException + */ + public void saveResource() throws IOException { + diResource.save(null); + } + + public void saveResource(IProgressMonitor monitor) throws IOException { + monitor.beginTask("Saving resources", 3); + monitor.worked(1); + saveResource(); + monitor.worked(1); + monitor.done(); + } + + + } +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditor.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditor.java new file mode 100644 index 00000000000..58fe0890268 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditor.java @@ -0,0 +1,176 @@ +/***************************************************************************** + * Copyright (c) 2009 CEA LIST & LIFL + * + * + * 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: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.example.core.sashwindows.fulleditor.editor; + + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.papyrus.example.core.sashwindows.fulleditor.texteditor.TextEditorPartModel; +import org.eclipse.papyrus.sasheditor.contentprovider.IContentChangedListener; +import org.eclipse.papyrus.sasheditor.contentprovider.ISashWindowsContentProvider; +import org.eclipse.papyrus.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider; +import org.eclipse.papyrus.sasheditor.editor.AbstractMultiPageSashEditor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.ide.IDE; + + +/** + * An example showing how to create a multi-page editor using sash windows. + * This example start with one page, and provide actions to create new pages. + * It can be used with the full sashWindow system (extends AbstractMultiPageSashEditor) or + * with the original Eclipse MultiPageEditor (extends MultiPageEditor). + * To use one or the other, change the extended class. + */ +public class MultiTextEditor extends /* MultiPageEditor */AbstractMultiPageSashEditor { + + /** + * A listener on model change events. + */ + IContentChangedListener contentChangedListener = new IContentChangedListener() { + + /** + * Called when the content is changed. RefreshTabs. + */ + public void contentChanged(ContentEvent event) { + System.out.println("contentChanged()"); + refreshTabs(); + } + }; + + /** + * The dirty flag. + */ + protected boolean isDirty = false; + + /** + * Listener on PROP_DIRTY event. Register the change. + */ + private IPropertyListener dirtyPropertyListener = new IPropertyListener() { + + public void propertyChanged(Object source, int propId) { + if(propId == PROP_DIRTY) + isDirty = true; + } + }; + + /** + * Creates a multi-page editor example. + */ + public MultiTextEditor() { + super(); + // ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + // Listen on dirty event. + addPropertyListener(dirtyPropertyListener); + } + + /** + * Create and initialize the pageProvider. + */ + protected ISashWindowsContentProvider createPageProvider() { + SimpleSashWindowsContentProvider pageProvider = new SimpleSashWindowsContentProvider(); + // Adding requested pages + pageProvider.addPage(new TextEditorPartModel()); + // Listen on contentProvider changes + pageProvider.addListener(contentChangedListener); + return pageProvider; + } + + + /** + * Get the ContentProvider casted to appropriate type. {@inheritDoc} + */ + @Override + protected SimpleSashWindowsContentProvider getContentProvider() { + return (SimpleSashWindowsContentProvider)super.getContentProvider(); + } + + /** + * The <code>MultiPageEditorPart</code> implementation of this <code>IWorkbenchPart</code> method disposes all nested editors. + * Subclasses may extend. + */ + public void dispose() { + // ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + getContentProvider().removeListener(contentChangedListener); + super.dispose(); + } + + /** + * Saves the multi-page editor's document. + */ + public void doSave(IProgressMonitor monitor) { + + IEditorPart editor = getActiveEditor(); + if(editor != null) { + editor.doSave(monitor); + // Reset dirty flag. + isDirty = false; + } + } + + /** + * Saves the multi-page editor's document as another file. + * Also updates the text for page 0's tab, and updates this multi-page editor's input + * to correspond to the nested editor's. + */ + public void doSaveAs() { + IEditorPart editor = getActiveEditor(); + if(editor != null) { + editor.doSaveAs(); + // setPageText(0, editor.getTitle()); + setInput(editor.getEditorInput()); + + // Reset dirty flag. + isDirty = false; + } + } + + /* + * (non-Javadoc) + * Method declared on IEditorPart + */ + public void gotoMarker(IMarker marker) { + // setActivePage(0); + IDE.gotoMarker(getActiveEditor(), marker); + } + + /** + * The <code>MultiPageEditorExample</code> implementation of this method + * checks that the input is an instance of <code>IFileEditorInput</code>. + */ + public void init(IEditorSite site, IEditorInput editorInput) + throws PartInitException { + if(!(editorInput instanceof IFileEditorInput)) + throw new PartInitException("Invalid Input: Must be IFileEditorInput"); + super.init(site, editorInput); + } + + /* + * (non-Javadoc) + * Method declared on IEditorPart. + */ + public boolean isSaveAsAllowed() { + return true; + } + + @Override + public boolean isDirty() { + return isDirty; + } + +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditorContributor.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditorContributor.java new file mode 100644 index 00000000000..b40bba76408 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditorContributor.java @@ -0,0 +1,132 @@ +/***************************************************************************** + * Copyright (c) 2009 CEA LIST & LIFL + * + * + * 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: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.example.core.sashwindows.fulleditor.editor; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.ide.IDEActionFactory; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +/** + * Manages the installation/deinstallation of global actions for multi-page editors. + * Responsible for the redirection of global actions to the active editor. + * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor. + */ +public class MultiTextEditorContributor extends MultiPageEditorActionBarContributor { + + private IEditorPart activeEditorPart; + + private Action sampleAction; + + /** + * Creates a multi-page contributor. + */ + public MultiTextEditorContributor() { + super(); + createActions(); + } + + /** + * Returns the action registed with the given text editor. + * + * @return IAction or null if editor is null. + */ + protected IAction getAction(ITextEditor editor, String actionID) { + return (editor == null ? null : editor.getAction(actionID)); + } + + /* + * (non-JavaDoc) + * Method declared in AbstractMultiPageEditorActionBarContributor. + */ + + public void setActivePage(IEditorPart part) { + if(activeEditorPart == part) + return; + + activeEditorPart = part; + + IActionBars actionBars = getActionBars(); + if(actionBars != null) { + + ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor)part : null; + + actionBars.setGlobalActionHandler( + ActionFactory.DELETE.getId(), + getAction(editor, ITextEditorActionConstants.DELETE)); + actionBars.setGlobalActionHandler( + ActionFactory.UNDO.getId(), + getAction(editor, ITextEditorActionConstants.UNDO)); + actionBars.setGlobalActionHandler( + ActionFactory.REDO.getId(), + getAction(editor, ITextEditorActionConstants.REDO)); + actionBars.setGlobalActionHandler( + ActionFactory.CUT.getId(), + getAction(editor, ITextEditorActionConstants.CUT)); + actionBars.setGlobalActionHandler( + ActionFactory.COPY.getId(), + getAction(editor, ITextEditorActionConstants.COPY)); + actionBars.setGlobalActionHandler( + ActionFactory.PASTE.getId(), + getAction(editor, ITextEditorActionConstants.PASTE)); + actionBars.setGlobalActionHandler( + ActionFactory.SELECT_ALL.getId(), + getAction(editor, ITextEditorActionConstants.SELECT_ALL)); + actionBars.setGlobalActionHandler( + ActionFactory.FIND.getId(), + getAction(editor, ITextEditorActionConstants.FIND)); + actionBars.setGlobalActionHandler( + IDEActionFactory.BOOKMARK.getId(), + getAction(editor, IDEActionFactory.BOOKMARK.getId())); + actionBars.updateActionBars(); + } + } + + private void createActions() { + sampleAction = new Action() { + + public void run() { + MessageDialog.openInformation(null, "Editor Plug-in", "Sample Action Executed"); + } + }; + sampleAction.setText("Sample Action"); + sampleAction.setToolTipText("Sample Action tool tip"); + sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); + } + + public void contributeToMenu(IMenuManager manager) { + IMenuManager menu = new MenuManager("Editor &Menu"); + manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); + menu.add(sampleAction); + } + + public void contributeToToolBar(IToolBarManager manager) { + manager.add(new Separator()); + manager.add(sampleAction); + } +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/CreateMessageCommandHandler.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/CreateMessageCommandHandler.java new file mode 100644 index 00000000000..f604d87bdf3 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/CreateMessageCommandHandler.java @@ -0,0 +1,90 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.core.sashwindows.fulleditor.msgpage;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.papyrus.sasheditor.contentprovider.IComponentModel;
+import org.eclipse.papyrus.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Command to create a new TextEditor.
+ * The command create a new IEditorModel and add it to the Sashwindow repository model.
+ *
+ * @author dumoulin
+ */
+public class CreateMessageCommandHandler extends AbstractHandler implements IHandler {
+
+ /**
+ * Method called when the command is invoked.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ // Create the Editor Model
+ IComponentModel model = new MessagePartModel("Message !!!");
+ // Get the Sashwindow model
+ ISashWindowsContentProvider contentProvider = getSashWindowsContentProvider();
+ if(contentProvider == null) {
+ showErrorDialog("Can't create Editor. Reason: Can't get current editor ContentProvider.");
+ }
+ // Add it to the current folder
+ contentProvider.addPage(model);
+ return null;
+ }
+
+
+ /**
+ * Show an ErrorDialog.
+ *
+ * @param string
+ */
+ private void showErrorDialog(String text) {
+ MessageBox dialog = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_WARNING | SWT.OK | SWT.APPLICATION_MODAL);
+ dialog.setText(text);
+ dialog.open();
+ return;
+ }
+
+
+ /**
+ * Get the current MultiDiagramEditor.
+ *
+ * @return
+ */
+ protected IEditorPart getMultiDiagramEditor() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editorPart = page.getActiveEditor();
+ return editorPart;
+ }
+
+ /**
+ * Get the shared object.
+ *
+ * @return
+ */
+ protected ISashWindowsContentProvider getSashWindowsContentProvider() {
+ IEditorPart editor = getMultiDiagramEditor();
+
+ ISashWindowsContentProvider contentProvider = (ISashWindowsContentProvider)editor.getAdapter(ISashWindowsContentProvider.class);
+ return contentProvider;
+ }
+
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/MessagePartModel.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/MessagePartModel.java new file mode 100644 index 00000000000..3d4ded09eed --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/MessagePartModel.java @@ -0,0 +1,73 @@ +package org.eclipse.papyrus.example.core.sashwindows.fulleditor.msgpage;
+
+import org.eclipse.papyrus.sasheditor.contentprovider.IComponentModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Description of the first page
+ *
+ * @author dumoulin
+ */
+
+public class MessagePartModel implements IComponentModel {
+
+ private String title;
+
+ private String msg;
+
+ static private int count = 0;
+
+
+ /**
+ *
+ */
+ public MessagePartModel(String msg) {
+ title = "newMsg " + count++;
+ this.msg = msg;
+ }
+
+ /**
+ * @param title
+ */
+ public MessagePartModel(String title, String msg) {
+ this.title = title;
+ this.msg = msg;
+ }
+
+ /**
+ * Return the control to be shown. {@inheritDoc}
+ */
+ public Composite createPartControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ FillLayout layout = new FillLayout();
+ composite.setLayout(layout);
+ StyledText text;
+
+ text = new StyledText(composite, SWT.H_SCROLL | SWT.V_SCROLL);
+ text.setEditable(false);
+
+ text.setText(" " + msg + " - " + getTabTitle());
+ return composite;
+ }
+
+ public Image getTabIcon() {
+ return null;
+ }
+
+ public String getTabTitle() {
+ return title;
+ }
+
+ /**
+ * Return this. In this implementation, the rawModel and the IEditorModel are the same.
+ *
+ */
+ public Object getRawModel() {
+ return this;
+ }
+
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/CreateTextEditorCommandHandler.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/CreateTextEditorCommandHandler.java new file mode 100644 index 00000000000..e8ccaf1563c --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/CreateTextEditorCommandHandler.java @@ -0,0 +1,90 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.core.sashwindows.fulleditor.texteditor;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.papyrus.sasheditor.contentprovider.IEditorModel;
+import org.eclipse.papyrus.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Command to create a new TextEditor.
+ * The command create a new IEditorModel and add it to the Sashwindow repository model.
+ *
+ * @author dumoulin
+ */
+public class CreateTextEditorCommandHandler extends AbstractHandler implements IHandler {
+
+ /**
+ * Method called when the command is invoked.
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ // Create the Editor Model
+ IEditorModel model = new TextEditorPartModel();
+ // Get the Sashwindow model
+ ISashWindowsContentProvider contentProvider = getSashWindowsContentProvider();
+ if(contentProvider == null) {
+ showErrorDialog("Can't create Editor. Reason: Can't get current editor ContentProvider.");
+ }
+ // Add it to the current folder
+ contentProvider.addPage(model);
+ return null;
+ }
+
+
+ /**
+ * Show an ErrorDialog.
+ *
+ * @param string
+ */
+ private void showErrorDialog(String text) {
+ MessageBox dialog = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_WARNING | SWT.OK | SWT.APPLICATION_MODAL);
+ dialog.setText(text);
+ dialog.open();
+ return;
+ }
+
+
+ /**
+ * Get the current MultiDiagramEditor.
+ *
+ * @return
+ */
+ protected IEditorPart getMultiDiagramEditor() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editorPart = page.getActiveEditor();
+ return editorPart;
+ }
+
+ /**
+ * Get the shared object.
+ *
+ * @return
+ */
+ protected ISashWindowsContentProvider getSashWindowsContentProvider() {
+ IEditorPart editor = getMultiDiagramEditor();
+
+ ISashWindowsContentProvider contentProvider = (ISashWindowsContentProvider)editor.getAdapter(ISashWindowsContentProvider.class);
+ return contentProvider;
+ }
+
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TabTextEditor.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TabTextEditor.java new file mode 100644 index 00000000000..838efb0a1af --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TabTextEditor.java @@ -0,0 +1,39 @@ +/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST & LIFL
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.core.sashwindows.fulleditor.texteditor;
+
+import org.eclipse.ui.editors.text.TextEditor;
+
+
+/**
+ * A TextEditor that can be used as Tab of a sashes window.
+ *
+ * @author dumoulin
+ */
+public class TabTextEditor extends TextEditor {
+
+ /**
+ *
+ */
+ public TabTextEditor() {
+ }
+
+ /**
+ * Set the name of this part. {@inheritDoc}
+ */
+ @Override
+ public void setPartName(String partName) {
+ super.setPartName(partName);
+ }
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TextEditorPartModel.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TextEditorPartModel.java new file mode 100644 index 00000000000..949e0d8fb17 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TextEditorPartModel.java @@ -0,0 +1,81 @@ +/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST & LIFL
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.core.sashwindows.fulleditor.texteditor;
+
+import org.eclipse.papyrus.sasheditor.contentprovider.IEditorModel;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorActionBarContributor;
+
+/**
+ * Description of the first page
+ *
+ * @author dumoulin
+ */
+
+public class TextEditorPartModel implements IEditorModel {
+
+ /** The text editor used in page 0. */
+ private TabTextEditor editor;
+
+ private String title;
+
+ static private int count = 0;
+
+ /**
+ * @param title
+ */
+ public TextEditorPartModel(String title) {
+ this.title = title;
+ }
+
+ /**
+ *
+ */
+ public TextEditorPartModel() {
+ title = "newText" + count++;
+ }
+
+ public IEditorPart createIEditorPart() throws PartInitException {
+ editor = new TabTextEditor();
+ if(title == null)
+ title = "newText" + count++;
+ return editor;
+ }
+
+ public Image getTabIcon() {
+ return null;
+ }
+
+ public String getTabTitle() {
+ return title;
+ }
+
+ /**
+ * Return this. In this implementation, the rawModel and the IEditorModel are the same.
+ *
+ */
+ public Object getRawModel() {
+ return this;
+ }
+
+ /**
+ * Return the ActionBarContributor dedicated to the created editor.
+ * Can return null if no particular ActionBarContributor is required.;
+ */
+ public EditorActionBarContributor getActionBarContributor() {
+ return null;
+ }
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizard.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizard.java new file mode 100644 index 00000000000..33bcefd6307 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizard.java @@ -0,0 +1,168 @@ +package org.eclipse.papyrus.example.core.sashwindows.fulleditor.wizards; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWizard; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; + +/** + * This is a sample new wizard. Its role is to create a new file + * resource in the provided container. If the container resource + * (a folder or a project) is selected in the workspace + * when the wizard is opened, it will accept it as the target + * container. The wizard creates one file with the extension + * "mte". If a sample multi-page editor (also available + * as a template) is registered for the same extension, it will + * be able to open it. + */ + +public class MultiTextNewWizard extends Wizard implements INewWizard { + + private MultiTextNewWizardPage page; + + private ISelection selection; + + /** + * Constructor for MultiTextNewWizard. + */ + public MultiTextNewWizard() { + super(); + setNeedsProgressMonitor(true); + } + + /** + * Adding the page to the wizard. + */ + + public void addPages() { + page = new MultiTextNewWizardPage(selection); + addPage(page); + } + + /** + * This method is called when 'Finish' button is pressed in + * the wizard. We will create an operation and run it + * using wizard as execution context. + */ + public boolean performFinish() { + final String containerName = page.getContainerName(); + final String fileName = page.getFileName(); + IRunnableWithProgress op = new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) throws InvocationTargetException { + try { + doFinish(containerName, fileName, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }; + try { + getContainer().run(true, false, op); + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + Throwable realException = e.getTargetException(); + MessageDialog.openError(getShell(), "Error", realException.getMessage()); + return false; + } + return true; + } + + /** + * The worker method. It will find the container, create the + * file if missing or just replace its contents, and open + * the editor on the newly created file. + */ + + private void doFinish( + String containerName, + String fileName, + IProgressMonitor monitor) + throws CoreException { + // create a sample file + monitor.beginTask("Creating " + fileName, 2); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource resource = root.findMember(new Path(containerName)); + if(!resource.exists() || !(resource instanceof IContainer)) { + throwCoreException("Container \"" + containerName + "\" does not exist."); + } + IContainer container = (IContainer)resource; + final IFile file = container.getFile(new Path(fileName)); + try { + InputStream stream = openContentStream(); + if(file.exists()) { + file.setContents(stream, true, true, monitor); + } else { + file.create(stream, true, monitor); + } + stream.close(); + } catch (IOException e) { + } + monitor.worked(1); + monitor.setTaskName("Opening file for editing..."); + getShell().getDisplay().asyncExec(new Runnable() { + + public void run() { + IWorkbenchPage page = + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try { + IDE.openEditor(page, file, true); + } catch (PartInitException e) { + } + } + }); + monitor.worked(1); + } + + /** + * We will initialize file contents with a sample text. + */ + + private InputStream openContentStream() { + String contents = + "This is the initial file contents for *.mte file that should be word-sorted in the Preview page of the multi-page editor"; + return new ByteArrayInputStream(contents.getBytes()); + } + + private void throwCoreException(String message) throws CoreException { + IStatus status = + new Status(IStatus.ERROR, "org.eclipse.example.multitext.editor", IStatus.OK, message, null); + throw new CoreException(status); + } + + /** + * We will accept the selection in the workbench to see if + * we can initialize from it. + * + * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.selection = selection; + } +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizardPage.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizardPage.java new file mode 100644 index 00000000000..5b67e140973 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizardPage.java @@ -0,0 +1,190 @@ +package org.eclipse.papyrus.example.core.sashwindows.fulleditor.wizards; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.IDialogPage; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; + +/** + * The "New" wizard page allows setting the container for the new file as well + * as the file name. The page will only accept file name without the extension + * OR with the extension that matches the expected one (mte). + */ + +public class MultiTextNewWizardPage extends WizardPage { + + private Text containerText; + + private Text fileText; + + private ISelection selection; + + /** + * Constructor for SampleNewWizardPage. + * + * @param pageName + */ + public MultiTextNewWizardPage(ISelection selection) { + super("wizardPage"); + setTitle("Sash Windows Full Editor File"); + setDescription("This wizard creates a new file with *.fullEditor extension that can be opened by a multi-page editor."); + this.selection = selection; + } + + /** + * @see IDialogPage#createControl(Composite) + */ + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + layout.numColumns = 3; + layout.verticalSpacing = 9; + Label label = new Label(container, SWT.NULL); + label.setText("&Container:"); + + containerText = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + containerText.setLayoutData(gd); + containerText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + + Button button = new Button(container, SWT.PUSH); + button.setText("Browse..."); + button.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + handleBrowse(); + } + }); + label = new Label(container, SWT.NULL); + label.setText("&File name:"); + + fileText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + fileText.setLayoutData(gd); + fileText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + initialize(); + dialogChanged(); + setControl(container); + } + + /** + * Tests if the current workbench selection is a suitable container to use. + */ + + private void initialize() { + if(selection != null && selection.isEmpty() == false + && selection instanceof IStructuredSelection) { + IStructuredSelection ssel = (IStructuredSelection)selection; + if(ssel.size() > 1) + return; + Object obj = ssel.getFirstElement(); + if(obj instanceof IResource) { + IContainer container; + if(obj instanceof IContainer) + container = (IContainer)obj; + else + container = ((IResource)obj).getParent(); + containerText.setText(container.getFullPath().toString()); + } + } + fileText.setText("new_file.fullEditor"); + } + + /** + * Uses the standard container selection dialog to choose the new value for + * the container field. + */ + + private void handleBrowse() { + ContainerSelectionDialog dialog = new ContainerSelectionDialog( + getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, + "Select new file container"); + if(dialog.open() == ContainerSelectionDialog.OK) { + Object[] result = dialog.getResult(); + if(result.length == 1) { + containerText.setText(((Path)result[0]).toString()); + } + } + } + + /** + * Ensures that both text fields are set. + */ + + private void dialogChanged() { + IResource container = ResourcesPlugin.getWorkspace().getRoot() + .findMember(new Path(getContainerName())); + String fileName = getFileName(); + + if(getContainerName().length() == 0) { + updateStatus("File container must be specified"); + return; + } + if(container == null + || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) { + updateStatus("File container must exist"); + return; + } + if(!container.isAccessible()) { + updateStatus("Project must be writable"); + return; + } + if(fileName.length() == 0) { + updateStatus("File name must be specified"); + return; + } + if(fileName.replace('\\', '/').indexOf('/', 1) > 0) { + updateStatus("File name must be valid"); + return; + } + int dotLoc = fileName.lastIndexOf('.'); + if(dotLoc != -1) { + String ext = fileName.substring(dotLoc + 1); + if(ext.equalsIgnoreCase("fullEditor") == false) { + updateStatus("File extension must be \"fullEditor\""); + return; + } + } + updateStatus(null); + } + + private void updateStatus(String message) { + setErrorMessage(message); + setPageComplete(message == null); + } + + public String getContainerName() { + return containerText.getText(); + } + + public String getFileName() { + return fileText.getText(); + } +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.classpath b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.classpath new file mode 100644 index 00000000000..2d1a4302f04 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.classpath @@ -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>
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.project b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.project new file mode 100644 index 00000000000..b1297849328 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.example.core.sashwindows.simpleeditor</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>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/META-INF/MANIFEST.MF b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..57f5cf06c81 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.example.core.sashwindows.simpleeditor;singleton:=true +Bundle-Version: 0.8.0.qualifier +Bundle-Activator: org.eclipse.papyrus.example.core.sashwindows.simpleeditor.Activator +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.eclipse.papyrus.sasheditor;bundle-version="0.7.0" +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Vendor: %providerName diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/build.properties b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/build.properties new file mode 100644 index 00000000000..4b8162ab8b2 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/build.properties @@ -0,0 +1,6 @@ +source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/icons/sample.gif b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/icons/sample.gif Binary files differnew file mode 100644 index 00000000000..34fb3c9d8cb --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/icons/sample.gif diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.properties b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.properties new file mode 100644 index 00000000000..8c92069cf64 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.properties @@ -0,0 +1,12 @@ +#################################################################################
+# Copyright (c) 2008 CEA LIST.
+# 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:
+# Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+##################################################################################
+pluginName=Papyrus sashwindows simple editor example
+providerName=Cedric Dumoulin
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.xml b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.xml new file mode 100644 index 00000000000..2ac9da5a09f --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="Sash Windows Simple Editor"
+ extensions="simpleEditor"
+ icon="icons/sample.gif"
+ contributorClass="org.eclipse.papyrus.example.core.sashwindows.simpleeditor.editors.MultiPageEditorContributor"
+ class="org.eclipse.papyrus.example.core.sashwindows.simpleeditor.editors.SimpleTextMultiPageEditor"
+ id="org.eclipse.papyrus.example.sashwindows.SimpleEditor">
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ name="Sash Windows Examples"
+ id="org.eclipse.papyrus.example.sashwindows">
+ </category>
+ <wizard
+ name="Sash Windows Simple Editor"
+ icon="icons/sample.gif"
+ category="org.eclipse.papyrus.example.sashwindows"
+ class="org.eclipse.papyrus.example.core.sashwindows.simpleeditor.wizards.MultiPageEditorNewWizard"
+ id="org.eclipse.papyrus.example.sashwindows.wizards.SimpleEditor">
+ </wizard>
+ </extension>
+
+</plugin>
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/Activator.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/Activator.java new file mode 100644 index 00000000000..76ea6ecfbdf --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/Activator.java @@ -0,0 +1,77 @@ +/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST & LIFL
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.core.sashwindows.simpleeditor;
+
+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
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.example.core";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (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 Activator 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);
+ }
+}
diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/MultiPageEditorContributor.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/MultiPageEditorContributor.java new file mode 100644 index 00000000000..aedb415c691 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/MultiPageEditorContributor.java @@ -0,0 +1,127 @@ +/***************************************************************************** + * Copyright (c) 2009 CEA LIST & LIFL + * + * + * 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: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.example.core.sashwindows.simpleeditor.editors; + +import org.eclipse.jface.action.*; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.ide.IDEActionFactory; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +/** + * Manages the installation/deinstallation of global actions for multi-page editors. + * Responsible for the redirection of global actions to the active editor. + * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor. + */ +public class MultiPageEditorContributor extends MultiPageEditorActionBarContributor { + + private IEditorPart activeEditorPart; + + private Action sampleAction; + + /** + * Creates a multi-page contributor. + */ + public MultiPageEditorContributor() { + super(); + createActions(); + } + + /** + * Returns the action registed with the given text editor. + * + * @return IAction or null if editor is null. + */ + protected IAction getAction(ITextEditor editor, String actionID) { + return (editor == null ? null : editor.getAction(actionID)); + } + + /* + * (non-JavaDoc) + * Method declared in AbstractMultiPageEditorActionBarContributor. + */ + + public void setActivePage(IEditorPart part) { + if(activeEditorPart == part) + return; + + activeEditorPart = part; + + IActionBars actionBars = getActionBars(); + if(actionBars != null) { + + ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor)part : null; + + actionBars.setGlobalActionHandler( + ActionFactory.DELETE.getId(), + getAction(editor, ITextEditorActionConstants.DELETE)); + actionBars.setGlobalActionHandler( + ActionFactory.UNDO.getId(), + getAction(editor, ITextEditorActionConstants.UNDO)); + actionBars.setGlobalActionHandler( + ActionFactory.REDO.getId(), + getAction(editor, ITextEditorActionConstants.REDO)); + actionBars.setGlobalActionHandler( + ActionFactory.CUT.getId(), + getAction(editor, ITextEditorActionConstants.CUT)); + actionBars.setGlobalActionHandler( + ActionFactory.COPY.getId(), + getAction(editor, ITextEditorActionConstants.COPY)); + actionBars.setGlobalActionHandler( + ActionFactory.PASTE.getId(), + getAction(editor, ITextEditorActionConstants.PASTE)); + actionBars.setGlobalActionHandler( + ActionFactory.SELECT_ALL.getId(), + getAction(editor, ITextEditorActionConstants.SELECT_ALL)); + actionBars.setGlobalActionHandler( + ActionFactory.FIND.getId(), + getAction(editor, ITextEditorActionConstants.FIND)); + actionBars.setGlobalActionHandler( + IDEActionFactory.BOOKMARK.getId(), + getAction(editor, IDEActionFactory.BOOKMARK.getId())); + actionBars.updateActionBars(); + } + } + + private void createActions() { + sampleAction = new Action() { + + public void run() { + MessageDialog.openInformation(null, "Core Plug-in", "Sample Action Executed"); + } + }; + sampleAction.setText("Sample Action"); + sampleAction.setToolTipText("Sample Action tool tip"); + sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); + } + + public void contributeToMenu(IMenuManager manager) { + IMenuManager menu = new MenuManager("Editor &Menu"); + manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu); + menu.add(sampleAction); + } + + public void contributeToToolBar(IToolBarManager manager) { + manager.add(new Separator()); + manager.add(sampleAction); + } +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/SimpleTextMultiPageEditor.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/SimpleTextMultiPageEditor.java new file mode 100644 index 00000000000..39c74b35f38 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/SimpleTextMultiPageEditor.java @@ -0,0 +1,325 @@ +/***************************************************************************** + * Copyright (c) 2009 CEA LIST & LIFL + * + * + * 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: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.example.core.sashwindows.simpleeditor.editors; + + +import java.io.StringWriter; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.StringTokenizer; + +import org.eclipse.core.resources.IMarker; +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.papyrus.sasheditor.contentprovider.IComponentModel; +import org.eclipse.papyrus.sasheditor.contentprovider.IEditorModel; +import org.eclipse.papyrus.sasheditor.contentprovider.ISashWindowsContentProvider; +import org.eclipse.papyrus.sasheditor.contentprovider.simple.SimpleSashWindowsContentProvider; +import org.eclipse.papyrus.sasheditor.multipage.editor.MultiPageEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FontDialog; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.part.EditorActionBarContributor; +import org.eclipse.ui.part.FileEditorInput; + +/** + * An example showing how to create a multi-page editor using a ContentProvider. + * This example is similar to the one provided by Eclipse wizard on MultiPage. + * + * This example has 3 pages: + * <ul> + * <li>page 0 contains a nested text editor. + * <li>page 1 allows you to change the font used in page 2 + * <li>page 2 shows the words in page 0 in sorted order + * </ul> + */ +public class SimpleTextMultiPageEditor extends MultiPageEditor implements IResourceChangeListener { + + /** The text editor used in page 0. */ + private TextEditor editor; + + /** The font chosen in page 1. */ + private Font font; + + /** The text widget used in page 2. */ + private StyledText text; + + /** + * Creates a multi-page editor example. + */ + public SimpleTextMultiPageEditor() { + super(); + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + } + + /** + * Create and initialize the pageProvider. + */ + protected ISashWindowsContentProvider createPageProvider() { + SimpleSashWindowsContentProvider pageProvider = new SimpleSashWindowsContentProvider(); + // Adding requested pages + pageProvider.addPage(new Page0()); + pageProvider.addPage(new Page1()); + pageProvider.addPage(new Page2()); + pageProvider.addPage(new Page0()); + + + return pageProvider; + } + + /** + * Description of the first page + * + * @author dumoulin + */ + public class Page0 implements IEditorModel { + + public IEditorPart createIEditorPart() throws PartInitException { + editor = new TextEditor(); + return editor; + } + + public Image getTabIcon() { + return null; + } + + public String getTabTitle() { + return editor.getTitle(); + } + + public Object getRawModel() { + return this; + } + + public EditorActionBarContributor getActionBarContributor() { + return null; + } + } + + /** + * Describe the page1 + * + * @author dumoulin + */ + public class Page1 implements IComponentModel { + + public Composite createPartControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + composite.setLayout(layout); + layout.numColumns = 2; + + Button fontButton = new Button(composite, SWT.NONE); + GridData gd = new GridData(GridData.BEGINNING); + gd.horizontalSpan = 2; + fontButton.setLayoutData(gd); + fontButton.setText("Change Font..."); + + fontButton.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent event) { + setFont(); + } + }); + + return composite; + } + + public Image getTabIcon() { + return null; + } + + public String getTabTitle() { + return "Properties"; + } + + public Object getRawModel() { + return this; + } + + } + + public class Page2 implements IComponentModel { + + public Composite createPartControl(Composite parent) { + Composite composite = new Composite(getContainer(), SWT.NONE); + FillLayout layout = new FillLayout(); + composite.setLayout(layout); + text = new StyledText(composite, SWT.H_SCROLL | SWT.V_SCROLL); + text.setEditable(false); + + return composite; + } + + public Image getTabIcon() { + return null; + } + + public String getTabTitle() { + return "Preview"; + } + + public Object getRawModel() { + return this; + } + + } + + /** + * The <code>MultiPageEditorPart</code> implementation of this <code>IWorkbenchPart</code> method disposes all nested editors. + * Subclasses may extend. + */ + public void dispose() { + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + super.dispose(); + } + + /** + * Saves the multi-page editor's document. + */ + public void doSave(IProgressMonitor monitor) { + getEditor(0).doSave(monitor); + } + + /** + * Saves the multi-page editor's document as another file. + * Also updates the text for page 0's tab, and updates this multi-page editor's input + * to correspond to the nested editor's. + */ + public void doSaveAs() { + IEditorPart editor = getEditor(0); + editor.doSaveAs(); + setPageText(0, editor.getTitle()); + setInput(editor.getEditorInput()); + } + + /* + * (non-Javadoc) + * Method declared on IEditorPart + */ + public void gotoMarker(IMarker marker) { + setActivePage(0); + IDE.gotoMarker(getEditor(0), marker); + } + + /** + * The <code>MultiPageEditorExample</code> implementation of this method + * checks that the input is an instance of <code>IFileEditorInput</code>. + */ + public void init(IEditorSite site, IEditorInput editorInput) + throws PartInitException { + if(!(editorInput instanceof IFileEditorInput)) + throw new PartInitException("Invalid Input: Must be IFileEditorInput"); + super.init(site, editorInput); + } + + /* + * (non-Javadoc) + * Method declared on IEditorPart. + */ + public boolean isSaveAsAllowed() { + return true; + } + + /** + * Calculates the contents of page 2 when the it is activated. + */ + protected void pageChange(int newPageIndex) { + super.pageChange(newPageIndex); + if(newPageIndex == 2) { + sortWords(); + } + } + + /** + * Closes all project files on project close. + */ + public void resourceChanged(final IResourceChangeEvent event) { + if(event.getType() == IResourceChangeEvent.PRE_CLOSE) { + Display.getDefault().asyncExec(new Runnable() { + + public void run() { + IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages(); + for(int i = 0; i < pages.length; i++) { + if(((FileEditorInput)editor.getEditorInput()).getFile().getProject().equals(event.getResource())) { + IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput()); + pages[i].closeEditor(editorPart, true); + } + } + } + }); + } + } + + /** + * Sets the font related data to be applied to the text in page 2. + */ + void setFont() { + FontDialog fontDialog = new FontDialog(getSite().getShell()); + fontDialog.setFontList(text.getFont().getFontData()); + FontData fontData = fontDialog.open(); + if(fontData != null) { + if(font != null) + font.dispose(); + font = new Font(text.getDisplay(), fontData); + text.setFont(font); + } + } + + /** + * Sorts the words in page 0, and shows them in page 2. + */ + void sortWords() { + + String editorText = + editor.getDocumentProvider().getDocument(editor.getEditorInput()).get(); + + StringTokenizer tokenizer = + new StringTokenizer(editorText, " \t\n\r\f!@#\u0024%^&*()-_=+`~[]{};:'\",.<>/?|\\"); + ArrayList editorWords = new ArrayList(); + while(tokenizer.hasMoreTokens()) { + editorWords.add(tokenizer.nextToken()); + } + + Collections.sort(editorWords, Collator.getInstance()); + StringWriter displayText = new StringWriter(); + for(int i = 0; i < editorWords.size(); i++) { + displayText.write(((String)editorWords.get(i))); + displayText.write(System.getProperty("line.separator")); + } + text.setText(displayText.toString()); + } +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizard.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizard.java new file mode 100644 index 00000000000..e7631ec0209 --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizard.java @@ -0,0 +1,168 @@ +/***************************************************************************** + * Copyright (c) 2009 CEA LIST & LIFL + * + * + * 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: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.example.core.sashwindows.simpleeditor.wizards; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.core.runtime.*; +import org.eclipse.jface.operation.*; +import java.lang.reflect.InvocationTargetException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.CoreException; +import java.io.*; +import org.eclipse.ui.*; +import org.eclipse.ui.ide.IDE; + +/** + * This is a sample new wizard. Its role is to create a new file + * resource in the provided container. If the container resource + * (a folder or a project) is selected in the workspace + * when the wizard is opened, it will accept it as the target + * container. The wizard creates one file with the extension + * "mpe". If a sample multi-page editor (also available + * as a template) is registered for the same extension, it will + * be able to open it. + */ + +public class MultiPageEditorNewWizard extends Wizard implements INewWizard { + + private MultiPageEditorNewWizardPage page; + + private ISelection selection; + + /** + * Constructor for MultiPageEditorNewWizard. + */ + public MultiPageEditorNewWizard() { + super(); + setNeedsProgressMonitor(true); + } + + /** + * Adding the page to the wizard. + */ + + public void addPages() { + page = new MultiPageEditorNewWizardPage(selection); + addPage(page); + } + + /** + * This method is called when 'Finish' button is pressed in + * the wizard. We will create an operation and run it + * using wizard as execution context. + */ + public boolean performFinish() { + final String containerName = page.getContainerName(); + final String fileName = page.getFileName(); + IRunnableWithProgress op = new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) throws InvocationTargetException { + try { + doFinish(containerName, fileName, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }; + try { + getContainer().run(true, false, op); + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + Throwable realException = e.getTargetException(); + MessageDialog.openError(getShell(), "Error", realException.getMessage()); + return false; + } + return true; + } + + /** + * The worker method. It will find the container, create the + * file if missing or just replace its contents, and open + * the editor on the newly created file. + */ + + private void doFinish( + String containerName, + String fileName, + IProgressMonitor monitor) + throws CoreException { + // create a sample file + monitor.beginTask("Creating " + fileName, 2); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IResource resource = root.findMember(new Path(containerName)); + if(!resource.exists() || !(resource instanceof IContainer)) { + throwCoreException("Container \"" + containerName + "\" does not exist."); + } + IContainer container = (IContainer)resource; + final IFile file = container.getFile(new Path(fileName)); + try { + InputStream stream = openContentStream(); + if(file.exists()) { + file.setContents(stream, true, true, monitor); + } else { + file.create(stream, true, monitor); + } + stream.close(); + } catch (IOException e) { + } + monitor.worked(1); + monitor.setTaskName("Opening file for editing..."); + getShell().getDisplay().asyncExec(new Runnable() { + + public void run() { + IWorkbenchPage page = + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try { + IDE.openEditor(page, file, true); + } catch (PartInitException e) { + } + } + }); + monitor.worked(1); + } + + /** + * We will initialize file contents with a sample text. + */ + + private InputStream openContentStream() { + String contents = + "This is the initial file contents for *.mpe file that should be word-sorted in the Preview page of the multi-page editor"; + return new ByteArrayInputStream(contents.getBytes()); + } + + private void throwCoreException(String message) throws CoreException { + IStatus status = + new Status(IStatus.ERROR, "org.eclipse.papyrus.example.core", IStatus.OK, message, null); + throw new CoreException(status); + } + + /** + * We will accept the selection in the workbench to see if + * we can initialize from it. + * + * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.selection = selection; + } +} diff --git a/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizardPage.java b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizardPage.java new file mode 100644 index 00000000000..79e1c6db2fc --- /dev/null +++ b/examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizardPage.java @@ -0,0 +1,202 @@ +/***************************************************************************** + * Copyright (c) 2009 CEA LIST & LIFL + * + * + * 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: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.example.core.sashwindows.simpleeditor.wizards; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; + +/** + * The "New" wizard page allows setting the container for the new file as well + * as the file name. The page will only accept file name without the extension + * OR with the extension that matches the expected one (mpe). + */ + +public class MultiPageEditorNewWizardPage extends WizardPage { + + private Text containerText; + + private Text fileText; + + private ISelection selection; + + /** + * Constructor for SampleNewWizardPage. + * + * @param pageName + */ + public MultiPageEditorNewWizardPage(ISelection selection) { + super("wizardPage"); + setTitle("Multi-page Editor File"); + setDescription("This wizard creates a new file with *.mpe extension that can be opened by a multi-page editor."); + this.selection = selection; + } + + /** + * @see IDialogPage#createControl(Composite) + */ + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + container.setLayout(layout); + layout.numColumns = 3; + layout.verticalSpacing = 9; + Label label = new Label(container, SWT.NULL); + label.setText("&Container:"); + + containerText = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + containerText.setLayoutData(gd); + containerText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + + Button button = new Button(container, SWT.PUSH); + button.setText("Browse..."); + button.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + handleBrowse(); + } + }); + label = new Label(container, SWT.NULL); + label.setText("&File name:"); + + fileText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + fileText.setLayoutData(gd); + fileText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + dialogChanged(); + } + }); + initialize(); + dialogChanged(); + setControl(container); + } + + /** + * Tests if the current workbench selection is a suitable container to use. + */ + + private void initialize() { + if(selection != null && selection.isEmpty() == false + && selection instanceof IStructuredSelection) { + IStructuredSelection ssel = (IStructuredSelection)selection; + if(ssel.size() > 1) + return; + Object obj = ssel.getFirstElement(); + if(obj instanceof IResource) { + IContainer container; + if(obj instanceof IContainer) + container = (IContainer)obj; + else + container = ((IResource)obj).getParent(); + containerText.setText(container.getFullPath().toString()); + } + } + fileText.setText("new_file.simpleEditor"); + } + + /** + * Uses the standard container selection dialog to choose the new value for + * the container field. + */ + + private void handleBrowse() { + ContainerSelectionDialog dialog = new ContainerSelectionDialog( + getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, + "Select new file container"); + if(dialog.open() == ContainerSelectionDialog.OK) { + Object[] result = dialog.getResult(); + if(result.length == 1) { + containerText.setText(((Path)result[0]).toString()); + } + } + } + + /** + * Ensures that both text fields are set. + */ + + private void dialogChanged() { + IResource container = ResourcesPlugin.getWorkspace().getRoot() + .findMember(new Path(getContainerName())); + String fileName = getFileName(); + + if(getContainerName().length() == 0) { + updateStatus("File container must be specified"); + return; + } + if(container == null + || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) { + updateStatus("File container must exist"); + return; + } + if(!container.isAccessible()) { + updateStatus("Project must be writable"); + return; + } + if(fileName.length() == 0) { + updateStatus("File name must be specified"); + return; + } + if(fileName.replace('\\', '/').indexOf('/', 1) > 0) { + updateStatus("File name must be valid"); + return; + } + int dotLoc = fileName.lastIndexOf('.'); + if(dotLoc != -1) { + String ext = fileName.substring(dotLoc + 1); + if(ext.equalsIgnoreCase("simpleEditor") == false) { + updateStatus("File extension must be \"simpleEditor\""); + return; + } + } + updateStatus(null); + } + + private void updateStatus(String message) { + setErrorMessage(message); + setPageComplete(message == null); + } + + public String getContainerName() { + return containerText.getText(); + } + + public String getFileName() { + return fileText.getText(); + } +} |