forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r219143 - in /forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views: NavigationView.java SiteXMLView.java TabsXMLView.java
Date Thu, 14 Jul 2005 23:59:11 GMT
Author: rgardler
Date: Thu Jul 14 16:59:09 2005
New Revision: 219143

URL: http://svn.apache.org/viewcvs?rev=219143&view=rev
Log:
start to refactor the views into an abstract class to ease maintenance - common code should
be moved into the new NavigatorView class

Added:
    forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/NavigationView.java
  (with props)
Modified:
    forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteXMLView.java
    forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/TabsXMLView.java

Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/NavigationView.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/NavigationView.java?rev=219143&view=auto
==============================================================================
--- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/NavigationView.java
(added)
+++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/NavigationView.java
Thu Jul 14 16:59:09 2005
@@ -0,0 +1,114 @@
+/*
+ * Copyright 1999-2005 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.views;
+
+import org.apache.forrest.eclipse.actions.Utilities;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.ViewPart;
+import org.w3c.dom.Document;
+
+/**
+ * An abstract class that provides common functionality for views that are 
+ * used to edit navigation documents such as site.xml and tabs.xml.
+ */
+public abstract class NavigationView extends ViewPart implements IMenuListener,
+        ISelectionListener {
+    protected TreeViewer treeViewer;
+    protected Document document;
+    protected String projectName;
+    protected String path;
+    protected IStructuredSelection treeSelection;
+    protected IProject activeProject;
+
+    /**
+     * 
+     */
+    public NavigationView() {
+        super();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createPartControl(Composite parent) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+     */
+    public void setFocus() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
+     */
+    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 site.xml file into this
+     * SiteXMLView.
+     */
+    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 + getFilename());
+                document = DOMUtilities.loadDOM(path);
+                treeViewer.setInput(document);
+            }
+        }
+    }
+
+    /**
+     * Get the name of the file this editor view represents.
+     * This name does not include the path. For example.
+     * 'site.xml' or 'tabs.xml'
+     * @return the name (without pat) of the document to view
+     */
+    protected abstract String getFilename();
+}

Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/NavigationView.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteXMLView.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteXMLView.java?rev=219143&r1=219142&r2=219143&view=diff
==============================================================================
--- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteXMLView.java
(original)
+++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteXMLView.java
Thu Jul 14 16:59:09 2005
@@ -20,17 +20,13 @@
 
 import java.util.ArrayList;
 
-import org.apache.forrest.eclipse.actions.Utilities;
 import org.apache.forrest.eclipse.wizards.NewSiteElement;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -45,14 +41,10 @@
 import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.ViewPart;
 import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -62,19 +54,11 @@
  * drop from the navigator and supports a number of context 
  * menus for editing. 
  */
-public class SiteXMLView extends ViewPart implements IMenuListener,
-		ISelectionListener {
-	private TreeViewer treeViewer;
-	private Document document;
-	private String projectName;
-	private String path;
-	private IStructuredSelection treeSelection;
+public class SiteXMLView extends NavigationView {
 	private Action AddElement;
 	private Action RemoveElement;
 	private Action SaveDocument;
 	
-	protected IProject activeProject;
-	
 	/**
 	 * The constructor.
 	 */
@@ -149,41 +133,6 @@
 		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 site.xml file into this
-     * SiteXMLView.
-	 */
-	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 + "site.xml");
-				document = DOMUtilities.loadDOM(path);
-				treeViewer.setInput(document);
-			}
-		}
-
-	}
-
     private void hookContextMenu() {
 		MenuManager menuMgr = new MenuManager("#PopupMenu");
 		menuMgr.setRemoveAllWhenShown(true);
@@ -256,6 +205,17 @@
 			"Sample View",
 			message);
 	}
+
+
+    /**
+     * Get the name of the file this editor view represents.
+     * This name does not include the path. For example.
+     * 'site.xml' or 'tabs.xml'
+     * @return the name (without pat) of the document to view
+     */
+    protected String getFilename() {
+        return "site.xml";
+    }
 
    
 	

Modified: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/TabsXMLView.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/TabsXMLView.java?rev=219143&r1=219142&r2=219143&view=diff
==============================================================================
--- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/TabsXMLView.java
(original)
+++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/TabsXMLView.java
Thu Jul 14 16:59:09 2005
@@ -20,17 +20,13 @@
 
 import java.util.ArrayList;
 
-import org.apache.forrest.eclipse.actions.Utilities;
 import org.apache.forrest.eclipse.wizards.NewTabElement;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -45,14 +41,10 @@
 import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.ViewPart;
 import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -62,18 +54,11 @@
  * drop from the navigator and supports a number of context 
  * menus for editing. 
  */
-public class TabsXMLView extends ViewPart implements IMenuListener,
-		ISelectionListener {
-	private TreeViewer tree;
-	private Document tabsDocument;
-	private String projectName;
-	private String path;
-	private IStructuredSelection treeSelection;
+public class TabsXMLView extends NavigationView {
 	private Action AddElement;
 	private Action RemoveElement;
 	private Action SaveDocument;
-	
-	protected IProject activeProject;
+    
 	/**
 	 * The constructor.
 	 */
@@ -84,12 +69,12 @@
 	 * it.
 	 */
 	public void createPartControl(Composite parent) {
-		tree = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
-		getSite().setSelectionProvider(tree);
+		treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+		getSite().setSelectionProvider(treeViewer);
 		int operations = DND.DROP_COPY | DND.DROP_MOVE;
 		Transfer[] types = new Transfer[] { FileTransfer.getInstance()};
 		//tree.addDropSupport(operations, types, new SiteDropListener(projectName ,tabsDocument,
tree));
-		tree.setContentProvider(new ITreeContentProvider() {
+		treeViewer.setContentProvider(new ITreeContentProvider() {
 			public Object[] getChildren(Object element) {
 				ArrayList ch = new ArrayList();
 				NodeList nl = ((Node) element).getChildNodes();
@@ -118,7 +103,7 @@
 					Object new_input) {
 			}
 		});
-		tree.setLabelProvider(new LabelProvider() {
+		treeViewer.setLabelProvider(new LabelProvider() {
 			public String getText(Object element) {
 				if (element instanceof Attr)
 					return "@" + ((Attr) element).getNodeName() + " " +((Attr) element).getNodeValue();
@@ -127,7 +112,7 @@
 			}
 		});
 		getViewSite().getPage().addSelectionListener(this);
-		tree.addSelectionChangedListener(new ISelectionChangedListener() {
+		treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
 		public void selectionChanged(SelectionChangedEvent event) {
 					if (event.getSelection() instanceof IStructuredSelection) {
 					IStructuredSelection selection = (IStructuredSelection) event
@@ -138,8 +123,8 @@
 		});
 	
 		//System.out.println(document.toString());
-		if (path != null) { tabsDocument = DOMUtilities.loadDOM(path);}
-		tree.setInput(tabsDocument);
+		if (path != null) { document = DOMUtilities.loadDOM(path);}
+		treeViewer.setInput(document);
 		makeActions();
 		hookContextMenu();
 	}
@@ -154,34 +139,6 @@
 
 	}
 
-	/**
-     * 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);
@@ -190,9 +147,9 @@
             TabsXMLView.this.fillContextMenu(manager);
 			}
 		});
-		Menu menu = menuMgr.createContextMenu(tree.getControl());
-		tree.getControl().setMenu(menu);
-		getSite().registerContextMenu(menuMgr, tree);
+		Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
+		treeViewer.getControl().setMenu(menu);
+		getSite().registerContextMenu(menuMgr, treeViewer);
 	}
 
 
@@ -208,11 +165,11 @@
 		AddElement = new Action() {
 			public void run() {
 				if (treeSelection != null) {
-					NewTabElement elementCreation_ = new NewTabElement(treeSelection,tabsDocument);
+					NewTabElement elementCreation_ = new NewTabElement(treeSelection,document);
 					elementCreation_.init(PlatformUI.getWorkbench(), null); // initializes the wizard
-					WizardDialog dialog = new WizardDialog(tree.getControl().getShell(), elementCreation_);
+					WizardDialog dialog = new WizardDialog(treeViewer.getControl().getShell(), elementCreation_);
 					dialog.open();
-				tree.refresh();
+				treeViewer.refresh();
 				}
 			}
 		};
@@ -228,7 +185,7 @@
 					Node deletionElement = (Element) treeSelection.getFirstElement();	
 					Node deletionParent = deletionElement.getParentNode();
 					deletionParent.removeChild(deletionElement);
-					tree.refresh();
+					treeViewer.refresh();
 					
 				}
 			}
@@ -240,7 +197,7 @@
 		
 		SaveDocument = new Action() {
 			public void run() {
-				DOMUtilities.SaveDOM(tabsDocument,path);
+				DOMUtilities.SaveDOM(document,path);
 			}
 		};
 		
@@ -252,11 +209,19 @@
 
 	private void showMessage(String message) {
 		MessageDialog.openInformation(
-			tree.getControl().getShell(),
+			treeViewer.getControl().getShell(),
 			"Sample View",
 			message);
 	}
 
-   
+    /**
+     * Get the name of the file this editor view represents.
+     * This name does not include the path. For example.
+     * 'site.xml' or 'tabs.xml'
+     * @return the name (without pat) of the document to view
+     */
+    protected String getFilename() {
+        return "tabs.xml";
+    }
 	
 }



Mime
View raw message