blob: e8ccaf1563ce84b9e95110e041c260c934c81245 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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;
}
}
|