summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert von Massow2011-03-02 10:23:49 (EST)
committer Sven Efftinge2011-03-02 11:46:54 (EST)
commit03420e150239d50490f19bb0cdcb3fd408e0b5dc (patch)
tree2d8adc7e47cc92940e09f8fedb76614d5c7b70c6
parentbda98294e743bbd63a7031ac31717a9034c59169 (diff)
downloadorg.eclipse.xtext-03420e150239d50490f19bb0cdcb3fd408e0b5dc.zip
org.eclipse.xtext-03420e150239d50490f19bb0cdcb3fd408e0b5dc.tar.gz
org.eclipse.xtext-03420e150239d50490f19bb0cdcb3fd408e0b5dc.tar.bz2
New class wizard
Signed-off-by: Sven Efftinge <sven.efftinge@itemis.de>
-rw-r--r--plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/NewXtend2ClassWizard.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/NewXtend2ClassWizard.java b/plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/NewXtend2ClassWizard.java
new file mode 100644
index 0000000..abc518c
--- /dev/null
+++ b/plugins/org.eclipse.xtext.xtend2.ui/src/org/eclipse/xtext/xtend2/ui/wizards/NewXtend2ClassWizard.java
@@ -0,0 +1,83 @@
+package org.eclipse.xtext.xtend2.ui.wizards;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Robert von Massow - Initial contribution and API
+ */
+@SuppressWarnings("restriction")
+public class NewXtend2ClassWizard extends NewElementWizard {
+
+ public static final String TITLE = "Xtend Class"; //$NON-NLS-1$
+
+ @Inject
+ private NewXtend2ClassWizardPage fPage;
+
+ public NewXtend2ClassWizard() {
+ setDefaultPageImageDescriptor(JavaPluginImages.DESC_WIZBAN_NEWCLASS);
+ setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
+ setWindowTitle(TITLE);
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ fPage.init(getSelection());
+ super.addPage(fPage);
+ }
+
+ @Override
+ protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
+ }
+
+ @Override
+ public IJavaElement getCreatedElement() {
+ return null;
+ }
+
+ @Override
+ public boolean performFinish() {
+ final int size = this.fPage.createType();
+ final IResource resource = fPage.getResource();
+ if(resource != null) {
+ selectAndReveal(resource);
+ final Display display= getShell().getDisplay();
+ display.asyncExec(new Runnable() {
+ public void run() {
+ IEditorPart editor;
+ try {
+ editor = IDE.openEditor(JavaPlugin.getActivePage(), (IFile) resource);
+ if (editor instanceof ITextEditor) {
+ final ITextEditor textEditor = (ITextEditor) editor;
+ ISelectionProvider selectionProvider = textEditor.getSelectionProvider();
+ ISelection selection = new TextSelection(size - 2, 0);
+ selectionProvider.setSelection(selection);
+ }
+ } catch (PartInitException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ return true;
+ } else {
+ return false;
+ }
+ }
+}