Search in sources :

Example 1 with JsJfaceNode

use of org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode in project webtools.sourceediting by eclipse.

the class StandardEditorActionsAction method delete.

private void delete(IAction action) {
    JsJfaceNode[] nodes = parseSelection();
    if (nodes == null || nodes.length == 0) {
        return;
    }
    IStructuredDocument lastDoc = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = null;
    try {
        int start;
        int length;
        for (int i = 0; i < nodes.length; i++) {
            JsJfaceNode currentNode = nodes[i];
            start = currentNode.getStartOffset();
            length = currentNode.getLength();
            IStructuredDocument doc = currentNode.getStructuredDocument();
            if (doc != lastDoc) {
                lastDoc = doc;
                if (model != null) {
                    model.endRecording(action);
                    model.changedModel();
                    model.releaseFromEdit();
                }
                if (modelManager != null) {
                    model = modelManager.getExistingModelForEdit(doc);
                    model.aboutToChangeModel();
                    model.beginRecording(action, "Delete JavaScript Element", "Delete JavaScript Element");
                }
            }
            // $NON-NLS-1$
            doc.replaceText(action, start, length, "");
        }
        model.endRecording(action);
    } catch (Exception e) {
        // $NON-NLS-1$
        System.out.println(Messages.getString("StandardEditorActionsAction.8") + e);
    } finally {
        if (model != null) {
            model.changedModel();
            model.releaseFromEdit();
        }
    }
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) JsJfaceNode(org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with JsJfaceNode

use of org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode in project webtools.sourceediting by eclipse.

the class StandardEditorActionsAction method paste.

private void paste(IAction action, boolean atEnd) {
    JsJfaceNode[] nodes = parseSelection();
    if (nodes == null || nodes.length == 0) {
        return;
    }
    int startOfPaste = -1;
    IStructuredDocument doc = null;
    /* Figure out where to paste the content */
    if (atEnd) {
        for (int i = 0; i < nodes.length; i++) {
            if ((nodes[i].getStartOffset() + nodes[i].getLength()) > startOfPaste) {
                startOfPaste = (nodes[i].getStartOffset() + nodes[i].getLength());
                doc = nodes[i].getStructuredDocument();
            }
        }
    } else {
        for (int i = 0; i < nodes.length; i++) {
            if ((nodes[i].getStartOffset() < startOfPaste || startOfPaste < 0)) {
                startOfPaste = nodes[i].getStartOffset();
                doc = nodes[i].getStructuredDocument();
            }
        }
    }
    Clipboard clipboard = null;
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = null;
    try {
        clipboard = new Clipboard(Display.getCurrent());
        String pasteString = (String) clipboard.getContents(TextTransfer.getInstance());
        model = modelManager.getExistingModelForEdit(doc);
        model.aboutToChangeModel();
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
        model.beginRecording(action, Messages.getString("StandardEditorActionsAction.9") + (atEnd ? Messages.getString("StandardEditorActionsAction.10") : Messages.getString("StandardEditorActionsAction.11")) + Messages.getString("StandardEditorActionsAction.12"), Messages.getString("StandardEditorActionsAction.13") + (atEnd ? Messages.getString("StandardEditorActionsAction.14") : Messages.getString("StandardEditorActionsAction.15")) + Messages.getString("StandardEditorActionsAction.16"));
        doc.replaceText(action, startOfPaste, 0, pasteString);
    } finally {
        if (clipboard != null) {
            clipboard.dispose();
        }
        if (model != null) {
            model.endRecording(action);
            model.changedModel();
            model.releaseFromEdit();
        }
    }
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) JsJfaceNode(org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Clipboard(org.eclipse.swt.dnd.Clipboard) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 3 with JsJfaceNode

use of org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode in project webtools.sourceediting by eclipse.

the class StandardEditorActionsAction method copy.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
	 *      org.eclipse.jface.viewers.ISelection)
	 */
private void copy(IAction action) {
    JsJfaceNode[] nodes = parseSelection();
    if (nodes == null || nodes.length == 0) {
        return;
    }
    Clipboard clipboard = null;
    StringBuffer text = new StringBuffer();
    if (StandardEditorActionsAction.APPEND_NEW_LINES_TO_COPY) {
        text.append(StandardEditorActionsAction.NEW_LINE);
    }
    try {
        for (int i = 0; i < nodes.length; i++) {
            JsJfaceNode currentNode = nodes[i];
            int start = currentNode.getStartOffset();
            int length = currentNode.getLength();
            IStructuredDocument doc = currentNode.getStructuredDocument();
            try {
                String elementText = doc.get(start, length);
                text.append(elementText);
            } catch (BadLocationException ex) {
                // TODO Auto-generated catch block
                ex.printStackTrace();
            }
            if (StandardEditorActionsAction.APPEND_NEW_LINES_TO_COPY) {
                text.append(StandardEditorActionsAction.NEW_LINE);
            }
            clipboard = new Clipboard(Display.getCurrent());
            clipboard.setContents(new Object[] { text.toString() }, new Transfer[] { TextTransfer.getInstance() });
        }
    } finally {
        if (clipboard != null) {
            clipboard.dispose();
        }
    }
}
Also used : JsJfaceNode(org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Clipboard(org.eclipse.swt.dnd.Clipboard) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with JsJfaceNode

use of org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode in project webtools.sourceediting by eclipse.

the class AddJavaDocStubAction method run.

public void run(IAction action) {
    IJavaScriptElement[] elements = JsElementActionProxy.getJsElementsFromSelection(selection);
    if (elements == null || elements.length < 1) {
        return;
    }
    IJavaScriptElement parent = elements[0].getParent();
    /* find the cu */
    while (parent != null && !(parent instanceof IJavaScriptUnit)) {
    }
    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((IJavaScriptUnit) parent, (IMember[]) members.toArray(new IMember[members.size()]), node[0]);
    }
}
Also used : IJavaScriptElement(org.eclipse.wst.jsdt.core.IJavaScriptElement) ArrayList(java.util.ArrayList) JsJfaceNode(org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode) IJavaScriptUnit(org.eclipse.wst.jsdt.core.IJavaScriptUnit) IMember(org.eclipse.wst.jsdt.core.IMember)

Aggregations

JsJfaceNode (org.eclipse.wst.jsdt.web.ui.views.contentoutline.JsJfaceNode)4 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Clipboard (org.eclipse.swt.dnd.Clipboard)2 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 ArrayList (java.util.ArrayList)1 IJavaScriptElement (org.eclipse.wst.jsdt.core.IJavaScriptElement)1 IJavaScriptUnit (org.eclipse.wst.jsdt.core.IJavaScriptUnit)1 IMember (org.eclipse.wst.jsdt.core.IMember)1