forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: rev 46120 - in forrest/trunk/scratchpad/eclipsePlugin: . src/org/apache/forrest/eclipse/wizards src/org/apache/forrest/template
Date Wed, 15 Sep 2004 16:12:42 GMT
Author: rgardler
Date: Wed Sep 15 09:12:40 2004
New Revision: 46120

Added:
   forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/wizards/NewXDoc.java
   forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/wizards/NewXdocPage.java
   forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/template/
   forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/template/new_xdoc.xml
Modified:
   forrest/trunk/scratchpad/eclipsePlugin/.project
   forrest/trunk/scratchpad/eclipsePlugin/plugin.xml
   forrest/trunk/scratchpad/eclipsePlugin/readme.txt
Log:
New XDoc wizard

Modified: forrest/trunk/scratchpad/eclipsePlugin/.project
==============================================================================
--- forrest/trunk/scratchpad/eclipsePlugin/.project	(original)
+++ forrest/trunk/scratchpad/eclipsePlugin/.project	Wed Sep 15 09:12:40 2004
@@ -29,6 +29,11 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>com.ibm.sse.model.structuredbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>

Modified: forrest/trunk/scratchpad/eclipsePlugin/plugin.xml
==============================================================================
--- forrest/trunk/scratchpad/eclipsePlugin/plugin.xml	(original)
+++ forrest/trunk/scratchpad/eclipsePlugin/plugin.xml	Wed Sep 15 09:12:40 2004
@@ -99,6 +99,11 @@
             project="true"
             name="Seed New Project"
             id="org.apache.forrest.eclipse.NewProjectWizard"/>
+      <wizard
+            class="org.apache.forrest.eclipse.wizards.NewXDoc"
+            category="org.apache.forrest.eclipse"
+            name="XDoc File"
+            id="org.apache.forrest.eclipse.wizards.NewXDoc"/>
    </extension>
 
 </plugin>

Modified: forrest/trunk/scratchpad/eclipsePlugin/readme.txt
==============================================================================
--- forrest/trunk/scratchpad/eclipsePlugin/readme.txt	(original)
+++ forrest/trunk/scratchpad/eclipsePlugin/readme.txt	Wed Sep 15 09:12:40 2004
@@ -5,6 +5,7 @@
 - Start and Stop Forrest
 - Build a Forrest site
 - Seed a new Project
+- Add a new XDoc to the project
 
 ============
 Installation
@@ -47,6 +48,13 @@
 
 - Select Deployable Plugins and Fragments and follow the wizard (easiest 
 to create directory structure directly in the eclipse installation 
-directory).
+directory otherwise you will need to manually install the generated
+files as a plugin for eclipse).
 
-- Restart Eclipse
\ No newline at end of file
+- Restart Eclipse
+
+============
+Known Issues
+============
+
+- If a project name has a space in it then the seeding of the project fails (problem with
Forrest core?)
\ No newline at end of file

Added: forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/wizards/NewXDoc.java
==============================================================================
--- (empty file)
+++ forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/wizards/NewXDoc.java
Wed Sep 15 09:12:40 2004
@@ -0,0 +1,161 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.eclipse.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;
+
+/**
+ * Create a new file XDoc
+ * 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
+ * "xml". When created the file is opened in the default editor.
+ */
+
+public class NewXDoc extends Wizard implements INewWizard {
+	private NewXdocPage page;
+	private ISelection selection;
+
+	/**
+	 * Constructor for NewXDoc.
+	 */
+	public NewXDoc() {
+		super();
+		setNeedsProgressMonitor(true);
+	}
+	
+	/**
+	 * Adding the page to the wizard.
+	 */
+
+	public void addPages() {
+		page = new NewXdocPage(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()) {
+				// FIXME: Inform the user the file exists
+			} 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.
+	 * This sample text is located in org/apache/forrest/template/new_xdoc.xml.
+	 */
+	private InputStream openContentStream() {
+		return this.getClass().getResourceAsStream("/org/apache/forrest/template/new_xdoc.xml");
+	}
+
+	private void throwCoreException(String message) throws CoreException {
+		IStatus status =
+			new Status(IStatus.ERROR, "org.apache.forrest.eclipse", 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;
+	}
+}
\ No newline at end of file

Added: forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/wizards/NewXdocPage.java
==============================================================================
--- (empty file)
+++ forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/eclipse/wizards/NewXdocPage.java
Wed Sep 15 09:12:40 2004
@@ -0,0 +1,175 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.forrest.eclipse.wizards;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.swt.events.*;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+import org.eclipse.jface.viewers.*;
+
+/**
+ * The "New" wizard page allows setting the container for
+ * the new xdoc 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 (xml).
+ */
+
+public class NewXdocPage extends WizardPage {
+	private Text containerText;
+	private Text fileText;
+	private ISelection selection;
+
+	/**
+	 * Create the new page.
+	 * @param pageName
+	 */
+	public NewXdocPage(ISelection selection) {
+		super("wizardPage");
+		setTitle("XDoc File");
+		setDescription("This wizard creates a new XDoc file with *.xml extension.");
+		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.xml");
+	}
+	
+	/**
+	 * 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]).toOSString());
+			}
+		}
+	}
+	
+	/**
+	 * Ensures that both text fields are set.
+	 */
+
+	private void dialogChanged() {
+		String container = getContainerName();
+		String fileName = getFileName();
+
+		if (container.length() == 0) {
+			updateStatus("File container must be specified");
+			return;
+		}
+		if (fileName.length() == 0) {
+			updateStatus("File name must be specified");
+			return;
+		}
+		int dotLoc = fileName.lastIndexOf('.');
+		if (dotLoc != -1) {
+			String ext = fileName.substring(dotLoc + 1);
+			if (ext.equalsIgnoreCase("xml") == false) {
+				updateStatus("File extension must be \"xml\"");
+				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();
+	}
+}
\ No newline at end of file

Added: forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/template/new_xdoc.xml
==============================================================================
--- (empty file)
+++ forrest/trunk/scratchpad/eclipsePlugin/src/org/apache/forrest/template/new_xdoc.xml	Wed
Sep 15 09:12:40 2004
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
+<document> 
+  <header> 
+    <title>New XDoc File</title> 
+  </header> 
+  <body> 
+    <!--  Add your content here -->
+  </body>
+</document>

Mime
View raw message