Search in sources :

Example 6 with DataObject

use of org.openide.loaders.DataObject in project netbeans-mmd-plugin by raydac.

the class MovePanel method initValues.

private void initValues() {
    final String text;
    if (this.files.length > 1) {
        text = String.format(BUNDLE.getString("MovePanel.multiFileText"), Integer.toString(this.files.length));
    } else {
        text = String.format(BUNDLE.getString("MovePanel.singleFileText"), this.files[0].getName());
    }
    this.labelMessage.setText(text);
    final List<Project> projects = new ArrayList<Project>();
    for (final Project p : OpenProjects.getDefault().getOpenProjects()) {
        projects.add(p);
    }
    final ComboBoxModel<Project> projectModel = new DefaultComboBoxModel<Project>(projects.toArray(new Project[projects.size()]));
    final ItemListener listener = new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (comboProjects.equals(e.getSource())) {
                updateFolders();
                parent.stateChanged(null);
            } else if (comboFolders.equals(e.getSource())) {
                parent.stateChanged(null);
            }
        }
    };
    this.comboProjects.addItemListener(listener);
    this.comboFolders.addItemListener(listener);
    this.comboProjects.setModel(projectModel);
    this.comboProjects.setSelectedItem(FileOwnerQuery.getOwner(this.files[0]));
    updateFolders();
    final ExplorerContext explorerContext = this.lookup.lookup(ExplorerContext.class);
    if (explorerContext != null) {
        final Node targetNode = explorerContext.getTargetNode();
        if (targetNode != null) {
            final DataObject dobj = targetNode.getLookup().lookup(DataObject.class);
            if (dobj != null) {
                final FileObject fo = dobj.getPrimaryFile();
                if (fo != null && fo.isValid() && fo.isFolder()) {
                    final Project proj = FileOwnerQuery.getOwner(fo);
                    if (proj != null) {
                        this.comboProjects.setSelectedItem(proj);
                        this.comboFolders.setSelectedItem(FileUtil.getRelativePath(proj.getProjectDirectory(), fo));
                    }
                }
            }
        }
    }
}
Also used : Project(org.netbeans.api.project.Project) ItemEvent(java.awt.event.ItemEvent) ExplorerContext(org.netbeans.modules.refactoring.api.ui.ExplorerContext) DataObject(org.openide.loaders.DataObject) Node(org.openide.nodes.Node) ArrayList(java.util.ArrayList) ItemListener(java.awt.event.ItemListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) FileObject(org.openide.filesystems.FileObject)

Example 7 with DataObject

use of org.openide.loaders.DataObject in project netbeans-mmd-plugin by raydac.

the class MindMapLink method writeUTF8Text.

public void writeUTF8Text(final String text) throws IOException {
    final FileObject foj = getFile();
    final FileLock flock = lock(foj);
    try {
        final OutputStream out = foj.getOutputStream(flock);
        try {
            IOUtils.write(text, out, "UTF-8");
        } finally {
            IOUtils.closeQuietly(out);
        }
    } finally {
        flock.releaseLock();
    }
    final DataObject doj = DataObject.find(foj);
    if (doj != null && doj instanceof MMDDataObject) {
        LOGGER.info("Notify about change primary file");
        ((MMDDataObject) doj).firePrimaryFileChanged();
    }
}
Also used : MMDDataObject(com.igormaznitsa.nbmindmap.nb.editor.MMDDataObject) DataObject(org.openide.loaders.DataObject) OutputStream(java.io.OutputStream) FileLock(org.openide.filesystems.FileLock) FileObject(org.openide.filesystems.FileObject) MMDDataObject(com.igormaznitsa.nbmindmap.nb.editor.MMDDataObject)

Example 8 with DataObject

use of org.openide.loaders.DataObject in project enclojure by EricThorsen.

the class ClojureToolTipAnnotation method getShortDescription.

public String getShortDescription() {
    LOG.log(Level.FINEST, "ClojureTooltip: getShortDescription");
    toolTipText = null;
    DebuggerEngine currentEngine = DebuggerManager.getDebuggerManager().getCurrentEngine();
    if (currentEngine == null)
        return null;
    JPDADebugger d = (JPDADebugger) currentEngine.lookupFirst(null, JPDADebugger.class);
    if (d == null)
        return null;
    Line.Part lp = (Line.Part) getAttachedAnnotatable();
    if (lp != null) {
        Line line = lp.getLine();
        DataObject dob = DataEditorSupport.findDataObject(line);
        EditorCookie ec = (EditorCookie) dob.getCookie(EditorCookie.class);
        if (ec != null) {
            // Only for editable dataobjects
            try {
                doc = ec.openDocument();
                RequestProcessor.getDefault().post(this);
            } catch (IOException e) {
            }
        }
    }
    return toolTipText;
}
Also used : DataObject(org.openide.loaders.DataObject) EditorCookie(org.openide.cookies.EditorCookie)

Example 9 with DataObject

use of org.openide.loaders.DataObject in project netbeans-php-enhancements by beberlei.

the class CodeSniffer method annotateWithCodingStandardHints.

private void annotateWithCodingStandardHints(FileObject fo, CodeSnifferXmlLogResult rs) {
    CodeSnifferFileListener l = new CodeSnifferFileListener();
    l.setLogResult(rs);
    fo.addFileChangeListener(l);
    try {
        DataObject d = DataObject.find(fo);
        LineCookie cookie = d.getCookie(LineCookie.class);
        Line.Set lineSet = null;
        Line line = null;
        for (int i = 0; i < rs.getCsErrors().size(); i++) {
            lineSet = cookie.getLineSet();
            line = lineSet.getOriginal(rs.getCsErrors().get(i).getLineNum());
            rs.getCsErrors().get(i).attach(line);
        }
        for (int i = 0; i < rs.getCsWarnings().size(); i++) {
            lineSet = cookie.getLineSet();
            line = lineSet.getOriginal(rs.getCsWarnings().get(i).getLineNum());
            rs.getCsWarnings().get(i).attach(line);
        }
    } catch (DataObjectNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : Line(org.openide.text.Line) LineCookie(org.openide.cookies.LineCookie) DataObject(org.openide.loaders.DataObject) DataObjectNotFoundException(org.openide.loaders.DataObjectNotFoundException)

Example 10 with DataObject

use of org.openide.loaders.DataObject in project netbeans-mmd-plugin by raydac.

the class MMDGraphEditor method drop.

@Override
public void drop(final DropTargetDropEvent dtde) {
    DataObject detectedDataObject = null;
    File detectedFileObject = null;
    String detectedNote = null;
    URI decodedLink = null;
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    try {
        final Object dataObjOrFile = extractDataObjectOrFileFromDnD(dtde);
        if (dataObjOrFile instanceof DataObject) {
            detectedDataObject = (DataObject) dataObjOrFile;
        } else {
            detectedFileObject = (File) dataObjOrFile;
        }
        final String detectedLink = DnDUtils.extractDropLink(dtde);
        detectedNote = DnDUtils.extractDropNote(dtde);
        if (detectedLink != null) {
            try {
                decodedLink = new URI(detectedLink);
            } catch (final URISyntaxException ex) {
                decodedLink = null;
            }
        }
        dtde.dropComplete(true);
    } catch (final Exception ex) {
        LOGGER.error("Can't extract data from DnD", ex);
        dtde.dropComplete(false);
    }
    final AbstractElement element = this.mindMapPanel.findTopicUnderPoint(dtde.getLocation());
    if (detectedDataObject != null) {
        addDataObjectToElement(detectedDataObject, element);
    } else if (detectedFileObject != null) {
        decodedLink = DnDUtils.extractUrlLinkFromFile(detectedFileObject);
        if (decodedLink != null) {
            addURItoElement(decodedLink, element);
        } else {
            addFileToElement(detectedFileObject, element);
        }
    } else if (decodedLink != null) {
        addURItoElement(decodedLink, element);
    } else if (detectedNote != null) {
        addNoteToElement(detectedNote, element);
    }
}
Also used : DataObject(org.openide.loaders.DataObject) AbstractElement(com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

DataObject (org.openide.loaders.DataObject)10 FileObject (org.openide.filesystems.FileObject)7 File (java.io.File)4 IOException (java.io.IOException)4 OpenCookie (org.openide.cookies.OpenCookie)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 BadLocationException (javax.swing.text.BadLocationException)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 Project (org.netbeans.api.project.Project)2 DataObjectNotFoundException (org.openide.loaders.DataObjectNotFoundException)2 Node (org.openide.nodes.Node)2 AbstractElement (com.igormaznitsa.mindmap.swing.panel.ui.AbstractElement)1 MMDDataObject (com.igormaznitsa.nbmindmap.nb.editor.MMDDataObject)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1