Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbchilds2007-06-14 13:54:25 +0000
committerbchilds2007-06-14 13:54:25 +0000
commit6858d6bd125b4576ca12436aec2da8de4452efaf (patch)
tree34780a2b3c6d25c0b1afc2a8e90f170735949470 /bundles/org.eclipse.wst.jsdt.web.ui/src/org
parentd332ebea3af3c6c74f83344b569e40c21ede573e (diff)
downloadwebtools.sourceediting-6858d6bd125b4576ca12436aec2da8de4452efaf.tar.gz
webtools.sourceediting-6858d6bd125b4576ca12436aec2da8de4452efaf.tar.xz
webtools.sourceediting-6858d6bd125b4576ca12436aec2da8de4452efaf.zip
minor enhancements for actions.
Diffstat (limited to 'bundles/org.eclipse.wst.jsdt.web.ui/src/org')
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubAction.java48
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubOperation.java100
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/SimpleJSDTActionProxy.java22
-rw-r--r--bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/views/contentoutline/JsJfaceNode.java3
4 files changed, 156 insertions, 17 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubAction.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubAction.java
index 374d0a12fe..02afc249ab 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubAction.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubAction.java
@@ -4,20 +4,26 @@
package org.eclipse.wst.jsdt.web.ui.actions;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.jsdt.core.ICompilationUnit;
+import org.eclipse.wst.jsdt.core.IJavaElement;
import org.eclipse.wst.jsdt.core.IMember;
import org.eclipse.wst.jsdt.internal.ui.actions.ActionMessages;
import org.eclipse.wst.jsdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler;
+import org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode;
/**
* @author childsb
@@ -26,30 +32,50 @@ import org.eclipse.wst.jsdt.internal.ui.util.ExceptionHandler;
public class AddJavaDocStubAction implements IObjectActionDelegate{
private IWorkbenchPart targetPart;
+ private ISelection selection;
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}
public void run(IAction action) {
- // TODO Auto-generated method stub
- System.out.println("Unimplemented method:AddJavaDocStubAction.run");
+
+ IJavaElement[] elements = JsElementActionProxy.getJsElementsFromSelection(selection);
+ if(elements==null || elements.length<1) return;
+
+ IJavaElement parent = elements[0].getParent();
+ /* find the cu */
+ while(parent!=null && !(parent instanceof ICompilationUnit));
+
+
+
+ if(parent!=null) {
+ ArrayList members = new ArrayList();
+ for(int i = 0;i<elements.length;i++) {
+ if(elements[i] instanceof IMember) {
+ members.add(elements[i]);
+ }
+ }
+ JsJfaceNode node[] = SimpleJSDTActionProxy.getJsJfaceNodesFromSelection(selection);
+ /* only should be one node */
+ run((ICompilationUnit)parent, (IMember[])members.toArray(new IMember[members.size()]),node[0] );
+
+
+ }
}
public void selectionChanged(IAction action, ISelection selection) {
- // TODO Auto-generated method stub
- System.out.println("Unimplemented method:AddJavaDocStubAction.selectionChanged");
-
+ this.selection = selection;
}
- public void run(ICompilationUnit cu, IMember[] members) {
+
+ public void run(ICompilationUnit cu, IMember[] members, JsJfaceNode node) {
try {
- AddJavaDocStubOperation op= new AddJavaDocStubOperation(members);
- PlatformUI.getWorkbench().getProgressService().runInUI(
- PlatformUI.getWorkbench().getProgressService(),
- new WorkbenchRunnableAdapter(op, op.getScheduleRule()),
- op.getScheduleRule());
+ AddJavaDocStubOperation op= new AddJavaDocStubOperation(members,node);
+ PlatformUI.getWorkbench().getProgressService().runInUI( PlatformUI.getWorkbench().getProgressService(),
+ new WorkbenchRunnableAdapter(op, op.getScheduleRule()),
+ op.getScheduleRule());
} catch (InvocationTargetException e) {
ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_error_actionFailed);
} catch (InterruptedException e) {
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubOperation.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubOperation.java
index 61c892941f..6ae3422955 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubOperation.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/AddJavaDocStubOperation.java
@@ -3,18 +3,108 @@
*/
package org.eclipse.wst.jsdt.web.ui.actions;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.projection.ProjectionDocument;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.text.edits.InsertEdit;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.wst.jsdt.core.ICompilationUnit;
import org.eclipse.wst.jsdt.core.IMember;
+import org.eclipse.wst.jsdt.internal.corext.codemanipulation.CodeGenerationMessages;
+import org.eclipse.wst.jsdt.web.core.internal.java.DocumentChangeListenerToTextEdit;
+import org.eclipse.wst.jsdt.web.core.internal.java.IJSPTranslation;
+import org.eclipse.wst.jsdt.web.core.internal.java.JSPTranslationExtension;
+import org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
/**
* @author childsb
- *
+ *
*/
public class AddJavaDocStubOperation extends org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddJavaDocStubOperation {
-
/**
* @param members
*/
- public AddJavaDocStubOperation(IMember[] members) {
+ private JsJfaceNode node;
+ private IDocument copy;
+ private DocumentChangeListenerToTextEdit textEditListener;
+;
+
+
+ public AddJavaDocStubOperation(IMember[] members, JsJfaceNode node) {
super(members);
- // TODO Auto-generated constructor stub
- }}
+ this.node = node;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.wst.jsdt.internal.corext.codemanipulation.AddJavaDocStubOperation#getDocument(org.eclipse.wst.jsdt.core.ICompilationUnit,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected IDocument getDocument(ICompilationUnit cu, IProgressMonitor monitor) throws CoreException {
+ return getJavaDocumentFromNode();
+ }
+
+ protected IDocument getJavaDocumentFromNode() {
+ if (copy == null) {
+ JSPTranslationExtension tran = (JSPTranslationExtension) node.getTranslation();
+ copy = new Document(tran.getJavaDocument().get());
+
+ textEditListener = new DocumentChangeListenerToTextEdit();
+ copy.addDocumentListener(textEditListener);
+ }
+ return copy;
+ }
+
+ public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
+ super.run(monitor);
+ applyChanges();
+ /* need to apply the text edits back to the original doc */
+ }
+
+ protected void applyChanges() {
+ IModelManager modelManager = StructuredModelManager.getModelManager();
+ IStructuredModel model = null;
+ IStructuredDocument doc = node.getStructuredDocument();
+ try {
+ MultiTextEdit edits = textEditListener.getTextEdits();
+
+ JSPTranslationExtension tran = (JSPTranslationExtension) node.getTranslation();
+ TextEdit[] jspEdit = tran.getJspEdits(edits);
+
+ model = modelManager.getExistingModelForEdit(doc);
+ model.aboutToChangeModel();
+ model.beginRecording(this, "Generate JsDoc", "Generate JsDoc");
+ for(int i = 0;i<jspEdit.length;i++) {
+ jspEdit[i].apply(doc);
+ }
+
+ } catch (MalformedTreeException ex) {
+ // TODO Auto-generated catch block
+ ex.printStackTrace();
+ } catch (BadLocationException ex) {
+ // TODO Auto-generated catch block
+ ex.printStackTrace();
+ } finally {
+ if (model != null) {
+ model.endRecording(this);
+ model.changedModel();
+ model.releaseFromEdit();
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/SimpleJSDTActionProxy.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/SimpleJSDTActionProxy.java
index dbda0a0f3c..20aa61b4b0 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/SimpleJSDTActionProxy.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/actions/SimpleJSDTActionProxy.java
@@ -6,6 +6,8 @@ package org.eclipse.wst.jsdt.web.ui.actions;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
@@ -19,7 +21,9 @@ import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.actions.ActionDelegate;
+import org.eclipse.wst.jsdt.core.IJavaElement;
import org.eclipse.wst.jsdt.ui.actions.ShowInNavigatorViewAction;
+import org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode;
/**
* @author childsb
@@ -164,4 +168,22 @@ public class SimpleJSDTActionProxy implements IObjectActionDelegate {
return actionHandlerTarget;
}
+ public static JsJfaceNode[] getJsJfaceNodesFromSelection(ISelection selection) {
+ if(selection==null) return new JsJfaceNode[0];
+ ArrayList elements = new ArrayList();
+
+ if(selection instanceof IStructuredSelection) {
+ Iterator itt = ((IStructuredSelection)selection).iterator();
+ while(itt.hasNext()) {
+ Object element = itt.next();
+ if(element instanceof JsJfaceNode) {
+ elements.add(element);
+ }
+
+ }
+ return (JsJfaceNode[])elements.toArray(new JsJfaceNode[elements.size()]);
+ }
+ return new JsJfaceNode[0];
+ }
+
}
diff --git a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/views/contentoutline/JsJfaceNode.java b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/views/contentoutline/JsJfaceNode.java
index d4c75d04e7..b92dd47791 100644
--- a/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/views/contentoutline/JsJfaceNode.java
+++ b/bundles/org.eclipse.wst.jsdt.web.ui/src/org/eclipse/wst/jsdt/web/ui/views/contentoutline/JsJfaceNode.java
@@ -216,7 +216,8 @@ public class JsJfaceNode extends ElementImpl implements IndexedRegion, INodeNoti
public IStructuredDocument getStructuredDocument() {
return ((NodeImpl) parent).getStructuredDocument();
}
- private JSPTranslation getTranslation() {
+
+ public JSPTranslation getTranslation() {
IStructuredModel model = null;
IModelManager modelManager = StructuredModelManager.getModelManager();

Back to the top