From 27925048d0dc96e5de7b9156d1c1bb51a3ee4fb0 Mon Sep 17 00:00:00 2001
From: cdumoulin
Date: Tue, 5 Apr 2011 15:39:01 +0000
Subject: ASSIGNED - bug 341927: [refactoring] Move extraplugins/core.example/*
--> examples/core/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=341927
---
.../.classpath | 7 +
.../.project | 28 ++
.../META-INF/MANIFEST.MF | 12 +
.../build.properties | 5 +
.../plugin.properties | 12 +
.../plugin.xml | 14 +
.../example/core/lifecycleevents/Activator.java | 50 ++++
.../LifeCycleEventsMonitorService.java | 142 +++++++++
.../.classpath | 7 +
.../.project | 28 ++
.../META-INF/MANIFEST.MF | 18 ++
.../build.properties | 6 +
.../icons/MsgTab.gif | Bin 0 -> 983 bytes
.../icons/TextEditor.gif | Bin 0 -> 983 bytes
.../icons/sample.gif | Bin 0 -> 983 bytes
.../plugin.properties | 12 +
.../plugin.xml | 135 +++++++++
.../core/sashwindows/fulleditor/Activator.java | 77 +++++
.../fulleditor/editor/DiMultiTextEditor.java | 331 +++++++++++++++++++++
.../fulleditor/editor/MultiTextEditor.java | 176 +++++++++++
.../editor/MultiTextEditorContributor.java | 132 ++++++++
.../msgpage/CreateMessageCommandHandler.java | 90 ++++++
.../fulleditor/msgpage/MessagePartModel.java | 73 +++++
.../texteditor/CreateTextEditorCommandHandler.java | 90 ++++++
.../fulleditor/texteditor/TabTextEditor.java | 39 +++
.../fulleditor/texteditor/TextEditorPartModel.java | 81 +++++
.../fulleditor/wizards/MultiTextNewWizard.java | 168 +++++++++++
.../fulleditor/wizards/MultiTextNewWizardPage.java | 190 ++++++++++++
.../.classpath | 7 +
.../.project | 28 ++
.../META-INF/MANIFEST.MF | 16 +
.../build.properties | 6 +
.../icons/sample.gif | Bin 0 -> 983 bytes
.../plugin.properties | 12 +
.../plugin.xml | 31 ++
.../core/sashwindows/simpleeditor/Activator.java | 77 +++++
.../editors/MultiPageEditorContributor.java | 127 ++++++++
.../editors/SimpleTextMultiPageEditor.java | 325 ++++++++++++++++++++
.../wizards/MultiPageEditorNewWizard.java | 168 +++++++++++
.../wizards/MultiPageEditorNewWizardPage.java | 202 +++++++++++++
40 files changed, 2922 insertions(+)
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.classpath
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/.project
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/META-INF/MANIFEST.MF
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/build.properties
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.properties
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/plugin.xml
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/Activator.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.lifecycleevents/src/org/eclipse/papyrus/example/core/lifecycleevents/LifeCycleEventsMonitorService.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.classpath
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/.project
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/META-INF/MANIFEST.MF
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/build.properties
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/MsgTab.gif
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/TextEditor.gif
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/icons/sample.gif
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.properties
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/plugin.xml
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/Activator.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/DiMultiTextEditor.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditor.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/editor/MultiTextEditorContributor.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/CreateMessageCommandHandler.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/msgpage/MessagePartModel.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/CreateTextEditorCommandHandler.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TabTextEditor.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/texteditor/TextEditorPartModel.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizard.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.fulleditor/src/org/eclipse/papyrus/example/core/sashwindows/fulleditor/wizards/MultiTextNewWizardPage.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.classpath
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/.project
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/META-INF/MANIFEST.MF
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/build.properties
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/icons/sample.gif
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.properties
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/plugin.xml
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/Activator.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/MultiPageEditorContributor.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/editors/SimpleTextMultiPageEditor.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizard.java
create mode 100644 examples/core/org.eclipse.papyrus.example.core.sashwindows.simpleeditor/src/org/eclipse/papyrus/example/core/sashwindows/simpleeditor/wizards/MultiPageEditorNewWizardPage.java
(limited to 'examples')
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 @@
+
+MultiPageEditorPart
implementation of this IWorkbenchPart
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 MultiPageEditorExample
implementation of this method
+ * checks that the input is an instance of IFileEditorInput
.
+ */
+ 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 MultiPageEditorPart
implementation of this IWorkbenchPart
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 MultiPageEditorExample
implementation of this method
+ * checks that the input is an instance of IFileEditorInput
.
+ */
+ 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 @@
+
+
MultiPageEditorPart
implementation of this IWorkbenchPart
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 MultiPageEditorExample
implementation of this method
+ * checks that the input is an instance of IFileEditorInput
.
+ */
+ 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();
+ }
+}
--
cgit v1.2.3