In progress: [Issue 215] Add a "new .proto file" wizard
Made the wizard look like Eclipse's "New File" wizard.
diff --git a/com.google.eclipse.protobuf.ui/.project b/com.google.eclipse.protobuf.ui/.project
index aa5cde0..51a1050 100644
--- a/com.google.eclipse.protobuf.ui/.project
+++ b/com.google.eclipse.protobuf.ui/.project
@@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
diff --git a/com.google.eclipse.protobuf.ui/plugin.xml b/com.google.eclipse.protobuf.ui/plugin.xml
index d8cb788..8edb1b1 100644
--- a/com.google.eclipse.protobuf.ui/plugin.xml
+++ b/com.google.eclipse.protobuf.ui/plugin.xml
@@ -2,16 +2,11 @@
<?eclipse version="3.0"?>
<plugin>
<extension point="org.eclipse.ui.editors">
- <editor
- class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
- contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
- default="true"
- icon="icons/pb.gif"
- id="com.google.eclipse.protobuf.Protobuf"
- name="%editor.name">
- <contentTypeBinding
- contentTypeId="com.google.eclipse.protobuf.Protobuf">
- </contentTypeBinding>
+ <editor class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
+ contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor" default="true" icon="icons/pb.gif"
+ id="com.google.eclipse.protobuf.Protobuf" name="%editor.name">
+ <contentTypeBinding contentTypeId="com.google.eclipse.protobuf.Protobuf">
+ </contentTypeBinding>
</editor>
</extension>
<extension point="org.eclipse.ui.handlers">
@@ -45,9 +40,7 @@
<and>
<reference definitionId="isActiveEditorAnInstanceOfXtextEditor" />
<with variable="activeEditor">
- <test
- property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
- value="com.google.eclipse.protobuf.Protobuf"
+ <test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName" value="com.google.eclipse.protobuf.Protobuf"
forcePluginActivation="true" />
</with>
</and>
@@ -56,64 +49,45 @@
<extension point="org.eclipse.ui.preferencePages">
<page
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.general.GeneralPreferencePage"
- id="com.google.eclipse.protobuf.Protobuf"
- name="%page.name">
+ id="com.google.eclipse.protobuf.Protobuf" name="%page.name">
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
- <page
- category="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
+ <page category="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:org.eclipse.xtext.ui.editor.syntaxcoloring.SyntaxColoringPreferencePage"
- id="com.google.eclipse.protobuf.Protobuf.coloring"
- name="%page.name.0">
+ id="com.google.eclipse.protobuf.Protobuf.coloring" name="%page.name.0">
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
- <page
- category="com.google.eclipse.protobuf.Protobuf"
+ <page category="com.google.eclipse.protobuf.Protobuf"
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.compiler.CompilerPreferencePage"
- id="com.google.eclipse.protobuf.ui.preferences.compiler.CompilerPreferencePage"
- name="%page.name.2">
+ id="com.google.eclipse.protobuf.ui.preferences.compiler.CompilerPreferencePage" name="%page.name.2">
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
- <page
- category="com.google.eclipse.protobuf.Protobuf"
+ <page category="com.google.eclipse.protobuf.Protobuf"
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
- id="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
- name="%page.name.4">
+ id="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage" name="%page.name.4">
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
- <page
- category="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
+ <page category="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.editor.save.SaveActionsPreferencePage"
- id="com.google.eclipse.protobuf.ui.preferences.editor.save.SaveActionsPreferencePage"
- name="%page.name.5">
+ id="com.google.eclipse.protobuf.ui.preferences.editor.save.SaveActionsPreferencePage" name="%page.name.5">
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
- <page
- category="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
+ <page category="com.google.eclipse.protobuf.ui.preferences.editor.general.EditorPreferencePage"
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.editor.numerictag.NumericTagPreferencePage"
- id="com.google.eclipse.protobuf.ui.preferences.editor.numerictag.NumericTagPreferencePage"
- name="%page.name.6">
+ id="com.google.eclipse.protobuf.ui.preferences.editor.numerictag.NumericTagPreferencePage" name="%page.name.6">
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
</extension>
<extension point="org.eclipse.ui.keywords">
- <keyword
- id="com.google.eclipse.protobuf.ui.keyword_Protobuf"
- label="%keyword.label" />
+ <keyword id="com.google.eclipse.protobuf.ui.keyword_Protobuf" label="%keyword.label" />
</extension>
<extension point="org.eclipse.ui.commands">
- <command
- description="%command.description"
- id="com.google.eclipse.protobuf.Protobuf.validate"
- name="%command.name">
+ <command description="%command.description" id="com.google.eclipse.protobuf.Protobuf.validate" name="%command.name">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?after=group.edit">
- <command
- commandId="com.google.eclipse.protobuf.Protobuf.validate"
- style="push"
- tooltip="%command.tooltip">
+ <command commandId="com.google.eclipse.protobuf.Protobuf.validate" style="push" tooltip="%command.tooltip">
<visibleWhen checkEnabled="false">
<reference definitionId="com.google.eclipse.protobuf.Protobuf.Editor.opened">
</reference>
@@ -178,24 +152,15 @@
</handler>
</extension>
<extension point="org.eclipse.ui.commands">
- <command
- description="%command.description.0"
- id="org.eclipse.xtext.ui.editor.outline.QuickOutline"
- name="%command.name.0">
+ <command description="%command.description.0" id="org.eclipse.xtext.ui.editor.outline.QuickOutline" name="%command.name.0">
</command>
- <command
- categoryId="org.eclipse.ui.category.textEditor"
- description="%command.description.1"
- id="com.google.eclipse.protobuf.ui.smartSemicolon"
- name="%command.name.1">
+ <command categoryId="org.eclipse.ui.category.textEditor" description="%command.description.1"
+ id="com.google.eclipse.protobuf.ui.smartSemicolon" name="%command.name.1">
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?after=group.open">
- <command
- commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline"
- style="push"
- tooltip="%command.tooltip.0">
+ <command commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline" style="push" tooltip="%command.tooltip.0">
<visibleWhen checkEnabled="false">
<reference definitionId="com.google.eclipse.protobuf.Protobuf.Editor.opened" />
</visibleWhen>
@@ -209,40 +174,29 @@
</markerResolutionGenerator>
</extension>
<extension point="org.eclipse.ui.bindings">
- <key
- commandId="com.google.eclipse.protobuf.ui.smartSemicolon"
- contextId="org.eclipse.xtext.ui.XtextEditorScope"
- schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
- sequence=";">
+ <key commandId="com.google.eclipse.protobuf.ui.smartSemicolon" contextId="org.eclipse.xtext.ui.XtextEditorScope"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" sequence=";">
</key>
</extension>
<extension point="org.eclipse.ui.propertyPages">
<page
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.general.GeneralPreferencePage"
- id="com.google.eclipse.protobuf.Protobuf"
- name="%page.name"
- selectionFilter="single">
+ id="com.google.eclipse.protobuf.Protobuf" name="%page.name" selectionFilter="single">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject">
</adapt>
</enabledWhen>
</page>
- <page
- category="com.google.eclipse.protobuf.Protobuf"
+ <page category="com.google.eclipse.protobuf.Protobuf"
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.compiler.CompilerPreferencePage"
- id="com.google.eclipse.protobuf.ui.properties.compiler.PropertyPage"
- name="%page.name.2"
- selectionFilter="single">
+ id="com.google.eclipse.protobuf.ui.properties.compiler.PropertyPage" name="%page.name.2" selectionFilter="single">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject" />
</enabledWhen>
</page>
- <page
- category="com.google.eclipse.protobuf.Protobuf"
+ <page category="com.google.eclipse.protobuf.Protobuf"
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferencePage"
- id="com.google.eclipse.protobuf.ui.properties.paths.PropertyPage"
- name="%page.name.3"
- selectionFilter="single">
+ id="com.google.eclipse.protobuf.ui.properties.paths.PropertyPage" name="%page.name.3" selectionFilter="single">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject" />
</enabledWhen>
@@ -253,10 +207,7 @@
class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.builder.protoc.ProtobufBuildParticipant">
</participant>
</extension>
- <extension
- id="protocMarker"
- name="%protoc.marker.name"
- point="org.eclipse.core.resources.markers">
+ <extension id="protocMarker" name="%protoc.marker.name" point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.problemmarker">
</super>
<super type="org.eclipse.core.resources.textmarker">
@@ -264,10 +215,7 @@
<persistent value="true">
</persistent>
</extension>
- <extension
- id="editorMarker"
- name="%editor.marker.name"
- point="org.eclipse.core.resources.markers">
+ <extension id="editorMarker" name="%editor.marker.name" point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.problemmarker">
</super>
<super type="org.eclipse.core.resources.textmarker">
@@ -288,9 +236,7 @@
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?after=group.edit">
- <command
- commandId="org.eclipse.xtext.ui.refactoring.RenameElement"
- style="push">
+ <command commandId="org.eclipse.xtext.ui.refactoring.RenameElement" style="push">
<visibleWhen checkEnabled="false">
<reference definitionId="com.google.eclipse.protobuf.Protobuf.Editor.opened">
</reference>
@@ -298,18 +244,16 @@
</command>
</menuContribution>
</extension>
- <extension
- point="org.eclipse.ui.newWizards">
- <category
- id="com.google.eclipse.protobuf.ui"
- name="Protocol Buffer">
- </category>
- <wizard
- category="com.google.eclipse.protobuf.ui"
- class="com.google.eclipse.protobuf.ui.wizards.NewProtoFileWizard"
- icon="icons/pb.gif"
- id="com.google.eclipse.protobuf.ui.wizards.NewProtoFileWizard"
- name="Protocol Buffer Descriptor File">
- </wizard>
+ <extension point="org.eclipse.ui.newWizards">
+ <category id="com.google.eclipse.protobuf.ui" name="Protocol Buffer">
+ </category>
+ <wizard category="com.google.eclipse.protobuf.ui" class="com.google.eclipse.protobuf.ui.wizards.NewProtoFileWizard"
+ icon="icons/pb.gif" id="com.google.eclipse.protobuf.ui.wizards.NewProtoFileWizard" name="Protocol Buffer Descriptor File">
+ </wizard>
</extension>
-</plugin>
+ <extension point="org.eclipse.ui.perspectiveExtensions">
+ <perspectiveExtension targetID="*">
+ <newWizardShortcut id="com.google.eclipse.protobuf.ui.wizards.NewProtoFileWizard" />
+ </perspectiveExtension>
+ </extension>
+</plugin>
\ No newline at end of file
diff --git a/com.google.eclipse.protobuf.ui/resources/newFileContents.proto b/com.google.eclipse.protobuf.ui/resources/newFileContents.proto
new file mode 100644
index 0000000..c17ce99
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/resources/newFileContents.proto
@@ -0,0 +1 @@
+syntax = "proto2";
\ No newline at end of file
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/Messages.java
new file mode 100644
index 0000000..09ba209
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/Messages.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012 Google Inc.
+ *
+ * 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
+ */
+package com.google.eclipse.protobuf.ui.wizards;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Messages extends NLS {
+ public static String pageDescription;
+ public static String pageTitle;
+ public static String wizardTitle;
+
+ static {
+ Class<Messages> type = Messages.class;
+ NLS.initializeMessages(type.getName(), type);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/Messages.properties b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/Messages.properties
new file mode 100644
index 0000000..be531fa
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/Messages.properties
@@ -0,0 +1,3 @@
+pageDescription=Create a new Protocol Buffer Definition file.
+pageTitle=Protocol Buffer Definition File
+wizardTitle=New Protocol Buffer Definition File
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizard.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizard.java
index 59c4936..75752ab 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizard.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizard.java
@@ -8,22 +8,14 @@
*/
package com.google.eclipse.protobuf.ui.wizards;
-import static com.google.common.io.Closeables.closeQuietly;
-import static com.google.eclipse.protobuf.ui.util.IStatusFactory.error;
import static com.google.eclipse.protobuf.ui.util.Workbenches.activeWorkbenchPage;
-import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
-import static org.eclipse.jface.dialogs.MessageDialog.openError;
-import static org.eclipse.ui.ide.IDE.openEditor;
+import static com.google.eclipse.protobuf.ui.wizards.Messages.wizardTitle;
-import java.io.*;
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.*;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.*;
+import org.eclipse.ui.ide.IDE;
/**
* Wizard for creation of new .proto files.
@@ -32,10 +24,10 @@
*/
public class NewProtoFileWizard extends Wizard implements INewWizard {
private NewProtoFileWizardPage page;
- private ISelection selection;
+ private IStructuredSelection selection;
public NewProtoFileWizard() {
- setNeedsProgressMonitor(true);
+ setWindowTitle(wizardTitle);
}
@Override public void addPages() {
@@ -44,64 +36,18 @@
}
@Override public boolean performFinish() {
- try {
- getContainer().run(true, false, new IRunnableWithProgress() {
- @Override public void run(IProgressMonitor monitor) throws InvocationTargetException {
- try {
- doFinish(page.containerName(), page.fileName(), monitor);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- } finally {
- monitor.done();
- }
- }
- });
- } catch (InterruptedException e) {
- return false;
- } catch (InvocationTargetException e) {
- Throwable realException = e.getTargetException();
- openError(getShell(), "Error", realException.getMessage());
+ final IFile file = page.createNewFile();
+ if (file == null) {
return false;
}
- return true;
- }
-
- private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException {
- monitor.beginTask("Creating " + fileName, 2);
- IResource resource = workspaceRoot().findMember(new Path(containerName));
- if (!resource.exists() || !(resource instanceof IContainer)) {
- throw new CoreException(error("Container \"" + containerName + "\" does not exist."));
- }
- IContainer container = (IContainer) resource;
- final IFile file = container.getFile(new Path(fileName));
- InputStream stream = null;
- try {
- stream = openContentStream();
- if (file.exists()) {
- file.setContents(stream, true, true, monitor);
- } else {
- file.create(stream, true, monitor);
- }
- } finally {
- closeQuietly(stream);
- }
- monitor.worked(1);
- monitor.setTaskName("Opening file for editing...");
getShell().getDisplay().asyncExec(new Runnable() {
@Override public void run() {
- IWorkbenchPage activePage = activeWorkbenchPage();
try {
- openEditor(activePage, file, true);
- } catch (PartInitException e) {
- }
+ IDE.openEditor(activeWorkbenchPage(), file, true);
+ } catch (PartInitException ignored) {}
}
});
- monitor.worked(1);
- }
-
- private InputStream openContentStream() {
- String contents = "syntax = \"proto2\";";
- return new ByteArrayInputStream(contents.getBytes());
+ return true;
}
@Override public void init(IWorkbench workbench, IStructuredSelection newSelection) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizardPage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizardPage.java
index e7f4588..e683466 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizardPage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/wizards/NewProtoFileWizardPage.java
@@ -8,155 +8,32 @@
*/
package com.google.eclipse.protobuf.ui.wizards;
-import static com.google.eclipse.protobuf.ui.util.Workspaces.workspaceRoot;
-import static org.eclipse.jface.window.Window.OK;
-import static org.eclipse.swt.SWT.*;
-import static org.eclipse.swt.layout.GridData.FILL_HORIZONTAL;
+import static com.google.eclipse.protobuf.ui.wizards.Messages.*;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.viewers.*;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+import java.io.*;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+
+import com.google.eclipse.protobuf.ui.internal.ProtobufActivator;
/**
* @author alruiz@google.com (Alex Ruiz)
*/
-public class NewProtoFileWizardPage extends WizardPage {
- private Text containerText;
- private Text fileText;
- private final ISelection selection;
-
- public NewProtoFileWizardPage(ISelection selection) {
- super("wizardPage");
- setTitle("Multi-page Editor File");
- setDescription("This wizard creates a new file with *.proto extension that can be opened by a multi-page editor.");
- this.selection = selection;
+public class NewProtoFileWizardPage extends WizardNewFileCreationPage {
+ public NewProtoFileWizardPage(IStructuredSelection selection) {
+ super("NewProtoFileWizardPage", selection); //$NON-NLS-1$
+ setTitle(pageTitle);
+ setDescription(pageDescription);
+ setFileExtension("proto");
+ setFileName("newFile.proto");
}
- @Override public void createControl(Composite parent) {
- Composite container = new Composite(parent, NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- layout.numColumns = 3;
- layout.verticalSpacing = 9;
- Label label = new Label(container, NULL);
- label.setText("&Container:");
-
- containerText = new Text(container, BORDER | SINGLE);
- containerText.setLayoutData(new GridData(FILL_HORIZONTAL));
- containerText.addModifyListener(new ModifyListener() {
- @Override public void modifyText(ModifyEvent e) {
- dialogChanged();
- }
- });
-
- Button button = new Button(container, PUSH);
- button.setText("Browse...");
- button.addSelectionListener(new SelectionAdapter() {
- @Override public void widgetSelected(SelectionEvent e) {
- handleBrowse();
- }
- });
- label = new Label(container, NULL);
- label.setText("&File name:");
-
- fileText = new Text(container, BORDER | SINGLE);
- fileText.setLayoutData(new GridData(FILL_HORIZONTAL));
- fileText.addModifyListener(new ModifyListener() {
- @Override public void modifyText(ModifyEvent e) {
- dialogChanged();
- }
- });
- initialize();
- dialogChanged();
- setControl(container);
- }
-
- private void initialize() {
- Object selected = firstSelectedElement();
- if (selected != null) {
- if (selected instanceof IResource) {
- IContainer container;
- if (selected instanceof IContainer) {
- container = (IContainer) selected;
- } else {
- container = ((IResource) selected).getParent();
- }
- containerText.setText(container.getFullPath().toString());
- }
- }
- fileText.setText("new_file.proto");
- }
-
- private Object firstSelectedElement() {
- if (selection == null || selection.isEmpty()) {
+ @Override protected InputStream getInitialContents() {
+ try {
+ return ProtobufActivator.getInstance().getBundle().getEntry("/resources/newFileContents.proto").openStream();
+ } catch (IOException e) {
return null;
}
- if (selection instanceof IStructuredSelection) {
- ((IStructuredSelection) selection).getFirstElement();
- }
- return null;
- }
-
- private void handleBrowse() {
- ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), workspaceRoot(), false,
- "Select new file container");
- if (dialog.open() == OK) {
- Object[] result = dialog.getResult();
- if (result.length == 1) {
- containerText.setText(((Path) result[0]).toString());
- }
- }
- }
-
- private void dialogChanged() {
- IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(containerName()));
- String fileName = fileName();
- if (containerName().isEmpty()) {
- 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.isEmpty()) {
- 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("proto") == false) {
- updateStatus("File extension must be \"proto\"");
- return;
- }
- }
- updateStatus(null);
- }
-
- private void updateStatus(String message) {
- setErrorMessage(message);
- setPageComplete(message == null);
- }
-
- public String containerName() {
- return containerText.getText();
- }
-
- public String fileName() {
- return fileText.getText();
}
}
\ No newline at end of file