Author: rgardler Date: Thu Jul 14 16:37:10 2005 New Revision: 219138 URL: http://svn.apache.org/viewcvs?rev=219138&view=rev Log: tabs view and wizards to add elements to both site and tabs view Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/DOMUtilities.java (with props) forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/TabsXMLView.java (with props) forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElement.java (with props) forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElementPage.java (with props) forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElement.java (with props) forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElementPage.java (with props) Modified: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/plugin.xml forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteXMLView.java Modified: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/plugin.xml URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/plugin.xml?rev=219138&r1=219137&r2=219138&view=diff ============================================================================== --- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/plugin.xml (original) +++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/plugin.xml Thu Jul 14 16:37:10 2005 @@ -126,14 +126,20 @@ + id="Forrest" + name="Forrest"/> + 0; + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object old_input, + Object new_input) { + } + }); + tree.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + if (element instanceof Attr) + return "@" + ((Attr) element).getNodeName() + " " +((Attr) element).getNodeValue(); + else + return ((Node) element).getNodeName(); + } + }); + getViewSite().getPage().addSelectionListener(this); + tree.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if (event.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) event + .getSelection(); + treeSelection = selection; + } + } + }); + + //System.out.println(document.toString()); + if (path != null) { tabsDocument = DOMUtilities.loadDOM(path);} + tree.setInput(tabsDocument); + makeActions(); + hookContextMenu(); + } + + public void setFocus() { + // TODO Auto-generated method stub + + } + + public void menuAboutToShow(IMenuManager manager) { + // TODO Auto-generated method stub + + } + + /** + * When the selection in the navigator view is changed + * we look to see if the new selection is an IProject. + * If it is then we load the tabs.xml file into this + * TabsXMLView. + */ + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if (selection instanceof IStructuredSelection) { + Object first = ((IStructuredSelection) selection).getFirstElement(); + IResource resource = (IResource) first; + if (resource instanceof IProject) { + activeProject = (IProject) resource; + projectName = activeProject.getProject().getName(); + path = (activeProject.getProject().getLocation() + .toString() + + java.io.File.separator + + Utilities.getPathToXDocs() + + java.io.File.separator + "tabs.xml"); + + tabsDocument = DOMUtilities.loadDOM(path); + tree.setInput(tabsDocument); + + + } + } + + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + TabsXMLView.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(tree.getControl()); + tree.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, tree); + } + + + + private void fillContextMenu(IMenuManager manager) { + manager.add(AddElement); + manager.add(RemoveElement); + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + manager.add(SaveDocument); + } + + private void makeActions() { + AddElement = new Action() { + public void run() { + if (treeSelection != null) { + NewTabElement elementCreation_ = new NewTabElement(treeSelection,tabsDocument); + elementCreation_.init(PlatformUI.getWorkbench(), null); // initializes the wizard + WizardDialog dialog = new WizardDialog(tree.getControl().getShell(), elementCreation_); + dialog.open(); + tree.refresh(); + } + } + }; + AddElement.setText("Add Element"); + AddElement.setToolTipText("Add Element tooltip"); + AddElement.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + + RemoveElement = new Action() { + public void run() { + if (treeSelection != null) { + //TODO: Code to remove Element does here. + Node deletionElement = (Element) treeSelection.getFirstElement(); + Node deletionParent = deletionElement.getParentNode(); + deletionParent.removeChild(deletionElement); + tree.refresh(); + + } + } + }; + RemoveElement.setText("DeleteElement"); + RemoveElement.setToolTipText("Delete Element"); + RemoveElement.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + + SaveDocument = new Action() { + public void run() { + DOMUtilities.SaveDOM(tabsDocument,path); + } + }; + + SaveDocument.setText("Save"); + SaveDocument.setToolTipText("Save XML Document"); + SaveDocument.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + } + + private void showMessage(String message) { + MessageDialog.openInformation( + tree.getControl().getShell(), + "Sample View", + message); + } + + + +} Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/TabsXMLView.java ------------------------------------------------------------------------------ svn:eol-style = native Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElement.java URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElement.java?rev=219138&view=auto ============================================================================== --- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElement.java (added) +++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElement.java Thu Jul 14 16:37:10 2005 @@ -0,0 +1,112 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation or its licensors, + * as applicable. + * + * 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 java.lang.reflect.InvocationTargetException; + +import org.apache.log4j.Logger; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.actions.WorkspaceModifyOperation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Create a new Site Element project. + */ + +public class NewSiteElement extends Wizard implements INewWizard { + protected IStructuredSelection selection; + private Document document; + + + /** + * Logger for this class + */ + private static final Logger logger = Logger + .getLogger(NewSiteElement.class); + + private NewSiteElementPage page; + + /** + * Constructor for New Site Element. + * @param treeSelection + * @param document + */ + public NewSiteElement(IStructuredSelection treeSelection, Document newDocument) { + super(); + setWindowTitle("New Element"); + setNeedsProgressMonitor(true); + selection= treeSelection; + document = newDocument; + } + + /** + * Adding the page to the wizard. + */ + + public void addPages() { + page = new NewSiteElementPage(); + 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() { + WorkspaceModifyOperation op= new WorkspaceModifyOperation() { + protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { + Node insertionElement = (Element) selection.getFirstElement(); + Element element = document.createElement(page.getElementName()); + element.setAttribute("href", page.getHref()); + element.setAttribute("description", page.getDescription()); + element.setAttribute("label", page.getLabel()); + insertionElement.appendChild(element); + } + }; + try { + getContainer().run(false, true, op); + } catch (InvocationTargetException e) { + return false; // TODO: should open error dialog and log + } catch (InterruptedException e) { + return false; // canceled + } + return true; + } + + + public void createControl(Composite parent) { + // TODO Auto-generated method stub + + } + + + + public void init(IWorkbench workbench, IStructuredSelection selection) { + // TODO Auto-generated method stub + + } +} + Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElement.java ------------------------------------------------------------------------------ svn:eol-style = native Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElementPage.java URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElementPage.java?rev=219138&view=auto ============================================================================== --- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElementPage.java (added) +++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElementPage.java Thu Jul 14 16:37:10 2005 @@ -0,0 +1,111 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation or its licensors, + * as applicable. + * + * 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.dialogs.IDialogPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * The "New Element" wizard page allows you to insert a + * new element into the site.xml file and specify the element + * name, location, path and descriotion. + * + */ + +public class NewSiteElementPage extends WizardPage { + + private Text hrefText; + private Text descriptionText; + private Text labelText; + private Text elementName; + + + /** + * Create the new page. + * @param selection + * @param selection + * @param pageName + */ + public NewSiteElementPage() { + super("wizardPage"); + setTitle("New Site Element"); + setDescription("This wizard creates a new element in site.xml."); + + } + + /** + * @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 = 2; + layout.verticalSpacing = 9; + Label label = new Label(container, SWT.NULL); + label.setText("&HREF:"); + + hrefText = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + hrefText.setLayoutData(gd); + + label = new Label(container, SWT.NULL); + label.setText("&Description:"); + + descriptionText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + descriptionText.setLayoutData(gd); + + label = new Label(container, SWT.NULL); + label.setText("&Label:"); + + labelText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + labelText.setLayoutData(gd); + + label = new Label(container, SWT.NULL); + label.setText("&Element Name:"); + + elementName = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + elementName.setLayoutData(gd); + setControl(container); + } + + public String getElementName() { + return elementName.getText(); + } + + public String getDescription() { + return descriptionText.getText(); + } + + public String getLabel() { + return labelText.getText(); + } + + public String getHref() { + return hrefText.getText(); + } + +} \ No newline at end of file Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewSiteElementPage.java ------------------------------------------------------------------------------ svn:eol-style = native Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElement.java URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElement.java?rev=219138&view=auto ============================================================================== --- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElement.java (added) +++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElement.java Thu Jul 14 16:37:10 2005 @@ -0,0 +1,113 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation or its licensors, + * as applicable. + * + * 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 java.lang.reflect.InvocationTargetException; + +import org.apache.log4j.Logger; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.actions.WorkspaceModifyOperation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Create a new Tab Element. + */ + +public class NewTabElement extends Wizard implements INewWizard { + protected IStructuredSelection selection; + private Document document; + + + /** + * Logger for this class + */ + private static final Logger logger = Logger + .getLogger(NewTabElement.class); + + private NewTabElementPage page; + + /** + * Constructor for New Tab Element. + * @param treeSelection + * @param document + */ + public NewTabElement(IStructuredSelection treeSelection, Document newDocument) { + super(); + setWindowTitle("New Element"); + setNeedsProgressMonitor(true); + selection= treeSelection; + document = newDocument; + } + + /** + * Adding the page to the wizard. + */ + + public void addPages() { + page = new NewTabElementPage(); + 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() { + WorkspaceModifyOperation op= new WorkspaceModifyOperation() { + protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { + Node insertionElement = (Element) selection.getFirstElement(); + Element element = document.createElement("tab"); + element.setAttribute("id", page.getId()); + element.setAttribute("label", page.getLabel()); + element.setAttribute("dir", page.getDir()); + element.setAttribute("indexfile", page.getIndexFile()); + insertionElement.appendChild(element); + } + }; + try { + getContainer().run(false, true, op); + } catch (InvocationTargetException e) { + return false; // TODO: should open error dialog and log + } catch (InterruptedException e) { + return false; // canceled + } + return true; + } + + + public void createControl(Composite parent) { + // TODO Auto-generated method stub + + } + + + + public void init(IWorkbench workbench, IStructuredSelection selection) { + // TODO Auto-generated method stub + + } +} + Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElement.java ------------------------------------------------------------------------------ svn:eol-style = native Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElementPage.java URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElementPage.java?rev=219138&view=auto ============================================================================== --- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElementPage.java (added) +++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElementPage.java Thu Jul 14 16:37:10 2005 @@ -0,0 +1,111 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation or its licensors, + * as applicable. + * + * 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.dialogs.IDialogPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * The "New Element" wizard page allows you to insert a + * new element into the site.xml file and specify the element + * name, location, path and descriotion. + * + */ + +public class NewTabElementPage extends WizardPage { + + private Text idText; + private Text dirText; + private Text labelText; + private Text indexFileText; + + + /** + * Create the new page. + * @param selection + * @param selection + * @param pageName + */ + public NewTabElementPage() { + super("wizardPage"); + setTitle("New Site Element"); + setDescription("This wizard creates a new element in site.xml."); + + } + + /** + * @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 = 2; + layout.verticalSpacing = 9; + Label label = new Label(container, SWT.NULL); + label.setText("&ID:"); + + idText = new Text(container, SWT.BORDER | SWT.SINGLE); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + idText.setLayoutData(gd); + + label = new Label(container, SWT.NULL); + label.setText("&Dir:"); + + dirText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + dirText.setLayoutData(gd); + + label = new Label(container, SWT.NULL); + label.setText("&Label:"); + + labelText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + labelText.setLayoutData(gd); + + label = new Label(container, SWT.NULL); + label.setText("&Index File:"); + + indexFileText = new Text(container, SWT.BORDER | SWT.SINGLE); + gd = new GridData(GridData.FILL_HORIZONTAL); + indexFileText.setLayoutData(gd); + setControl(container); + } + + public String getId() { + return idText.getText(); + } + + public String getDir() { + return dirText.getText(); + } + + public String getLabel() { + return labelText.getText(); + } + + public String getIndexFile() { + return indexFileText.getText(); + } + +} \ No newline at end of file Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/wizards/NewTabElementPage.java ------------------------------------------------------------------------------ svn:eol-style = native