forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgard...@apache.org
Subject svn commit: r209549 - in /forrest/trunk/tools/eclipse/plugins/org.apache.forrest: plugin.xml src/org/apache/forrest/eclipse/views/SiteDropListener.java src/org/apache/forrest/eclipse/views/SiteXMLView.java
Date Thu, 07 Jul 2005 00:13:53 GMT
Author: rgardler
Date: Wed Jul  6 17:13:51 2005
New Revision: 209549

URL: http://svn.apache.org/viewcvs?rev=209549&view=rev
Log:
Add initial support for context menus and drag and drop (thanks to Anil Ramnanan, FOR-565).
Added basic javadocs.

Added:
    forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteDropListener.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=209549&r1=209548&r2=209549&view=diff
==============================================================================
--- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/plugin.xml (original)
+++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/plugin.xml Wed Jul  6 17:13:51
2005
@@ -135,4 +135,14 @@
            id="SiteXML"
            name="SiteXML"/>
   </extension>
+  
+   <extension
+         id="treeDrop"
+         name="Site XML Drop"
+         point="org.eclipse.ui.dropActions">
+      <action
+            class="org.apache.forrest.eclipse.views.SiteXMLView"
+            id="SiteXMLDrop">
+      </action>
+   </extension>
 </plugin>

Added: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteDropListener.java
URL: http://svn.apache.org/viewcvs/forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteDropListener.java?rev=209549&view=auto
==============================================================================
--- forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteDropListener.java
(added)
+++ forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteDropListener.java
Wed Jul  6 17:13:51 2005
@@ -0,0 +1,100 @@
+/*
+ * 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 java.io.File;
+
+import org.apache.forrest.eclipse.actions.Utilities;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.DropTargetListener;
+import org.eclipse.swt.widgets.Display;
+import org.w3c.dom.Document;
+
+/**
+ * Handles dropping of files onto the siteXMLView.
+ *
+ */
+public class SiteDropListener implements DropTargetListener {
+
+
+    TreeViewer treeViewer;
+
+    Document document;
+    
+    String projectName;
+    
+    final Display display = Display.getDefault();
+    
+    public SiteDropListener(String projectName, Document document, TreeViewer treeViewer)
{
+        // TODO Auto-generated constructor stub
+        this.treeViewer = treeViewer;
+        this.document = document;
+        this.projectName = projectName;
+    }
+
+    public void dragEnter(DropTargetEvent event) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void dragLeave(DropTargetEvent event) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void dragOperationChanged(DropTargetEvent event) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void dragOver(DropTargetEvent event) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Handle files that are dropped into the site tree. 
+     */
+    public void drop(DropTargetEvent event) {
+        if (event.data instanceof String[]) {
+            String[] files = (String[]) event.data;
+            File strFilename;
+            String filePath = null;
+            String localItemPath;
+            String itemPath;
+            for (int i = 0; i < files.length; i++) {
+                strFilename = new File(files[i]);
+                filePath = strFilename.getPath();
+                localItemPath = filePath.substring(filePath
+                        .indexOf("xdocs")
+                        + "xdocs".length() + 1);
+                itemPath = filePath.substring(Utilities
+                        .getPathToXDocs().length() + 2);
+                //TODO: Code to add element from drag and drop goes here
+       
+                
+            }
+        }
+    }
+
+    public void dropAccept(DropTargetEvent event) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Propchange: forrest/trunk/tools/eclipse/plugins/org.apache.forrest/src/org/apache/forrest/eclipse/views/SiteDropListener.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=209549&r1=209548&r2=209549&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
Wed Jul  6 17:13:51 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation or its licensors,
+ * Copyright 1999-2005 The Apache Software Foundation or its licensors,
  * as applicable.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,54 +27,72 @@
 import org.apache.forrest.eclipse.actions.Utilities;
 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;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
+
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerSorter;
+
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
+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.NamedNodeMap;
+
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
+
+
 /**
- * This sample class demonstrates how to plug-in a new workbench view. The view
- * shows data obtained from the model. The sample creates a dummy model on the
- * fly, but a real implementation would connect to the model available either in
- * this or another plug-in (e.g. the workspace). The view is connected to the
- * model using a content provider.
- * <p>
- * The view uses a label provider to define how model objects should be
- * presented in the view. Each view can present the same model objects using
- * different labels and icons, if needed. Alternatively, a single label provider
- * can be shared between views in order to ensure that objects of the same type
- * are presented in the same way everywhere.
- * <p>
+ * A tree view for site.xml files. The view handles drag and
+ * drop from the navigator and supports a number of context 
+ * menus for editing. 
  */
-
 public class SiteXMLView extends ViewPart implements IMenuListener,
 		ISelectionListener {
-	private TreeViewer viewer;
-
-	private IProject activeProject;
+	private TreeViewer treeViewer;
 
 	private DocumentBuilder parser;
 
 	private Document document;
+	
+	private String projectName;
+		
+	private IStructuredSelection treeSelection;
+	
+	private Action AddElement;
+	
+	private Action RemoveElement;
+	
+	protected IProject activeProject;
+	
+	protected Composite parent;
+	
+	
 
 	/*
 	 * The content provider class is responsible for providing objects to the
@@ -84,9 +102,7 @@
 	 * example).
 	 */
 
-	class NameSorter extends ViewerSorter {
-	}
-
+	
 	/**
 	 * The constructor.
 	 */
@@ -98,15 +114,14 @@
 	 * it.
 	 */
 	public void createPartControl(Composite parent) {
-		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
-		getSite().setSelectionProvider(viewer);
-		viewer.setContentProvider(new ITreeContentProvider() {
+		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()};
+		treeViewer.addDropSupport(operations, types, new SiteDropListener(projectName ,document,
treeViewer));
+		treeViewer.setContentProvider(new ITreeContentProvider() {
 			public Object[] getChildren(Object element) {
 				ArrayList ch = new ArrayList();
-				NamedNodeMap atrs = ((Node) element).getAttributes();
-				if (atrs != null)
-					for (int i = 0; i < atrs.getLength(); i++)
-						ch.add(atrs.item(i));
 				NodeList nl = ((Node) element).getChildNodes();
 				for (int i = 0; i < nl.getLength(); i++)
 					if (nl.item(i).getNodeType() == Node.ELEMENT_NODE)
@@ -134,10 +149,10 @@
 			}
 		});
 
-		viewer.setLabelProvider(new LabelProvider() {
+		treeViewer.setLabelProvider(new LabelProvider() {
 			public String getText(Object element) {
 				if (element instanceof Attr)
-					return "@" + ((Attr) element).getNodeName();
+					return "@" + ((Attr) element).getNodeName() + " " +((Attr) element).getNodeValue();
 				else
 					return ((Node) element).getNodeName();
 			}
@@ -160,22 +175,25 @@
 			e.printStackTrace();
 		}
 		getViewSite().getPage().addSelectionListener(this);
-		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
-			public void selectionChanged(SelectionChangedEvent event) {
-				Text text = null;
-				// if the selection is empty clear the label
-				if (event.getSelection().isEmpty()) {
-					text.setText("");
-					return;
-				}
-				if (event.getSelection() instanceof IStructuredSelection) {
+		
+		
+		treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+		
+		public void selectionChanged(SelectionChangedEvent event) {
+					if (event.getSelection() instanceof IStructuredSelection) {
 					IStructuredSelection selection = (IStructuredSelection) event
 							.getSelection();
-
+					treeSelection = selection;
+					
+					
 				}
 			}
 		});
-		// viewer.setInput(document);
+	
+		//System.out.println(document.toString());
+		treeViewer.setInput(document);
+		makeActions();
+		hookContextMenu();
 	}
 
 	public void setFocus() {
@@ -188,12 +206,14 @@
 
 	}
 
+	
 	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;
+				String projectName = activeProject.getProject().getName();
 				String path = (activeProject.getProject().getLocation()
 						.toString()
 						+ java.io.File.separator
@@ -208,12 +228,67 @@
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}
-				viewer.setInput(document);
-
+				treeViewer.setInput(document);
+	
 			}
 		}
 
 	}
 
+		private void hookContextMenu() {
+		MenuManager menuMgr = new MenuManager("#PopupMenu");
+		menuMgr.setRemoveAllWhenShown(true);
+		menuMgr.addMenuListener(new IMenuListener() {
+			public void menuAboutToShow(IMenuManager manager) {
+            SiteXMLView.this.fillContextMenu(manager);
+			}
+		});
+		Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
+		treeViewer.getControl().setMenu(menu);
+		getSite().registerContextMenu(menuMgr, treeViewer);
+	}
+
+
+
+	private void fillContextMenu(IMenuManager manager) {
+		manager.add(AddElement);
+		manager.add(RemoveElement);
+		// Other plug-ins can contribute there actions here
+		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+	}
 	
+
+	private void makeActions() {
+		AddElement = new Action() {
+			public void run() {
+				if (treeSelection != null) {
+				//TODO: Code to add Element goes here
+				}
+			}
+		};
+		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.
+					}
+			}
+		};
+		RemoveElement.setText("DeleteElement");
+		RemoveElement.setToolTipText("Delete Element");
+		RemoveElement.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+	}
+
+	private void showMessage(String message) {
+		MessageDialog.openInformation(
+			treeViewer.getControl().getShell(),
+			"Sample View",
+			message);
+	}
+
 }



Mime
View raw message