Search in sources :

Example 1 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 2 with DataObject

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

the class CodeSnifferAction method getFileObject.

/**
 * Copied from org.netbeans.modules.php.project.ui.actions.support.CommandUtils
 *
 * @param node
 * @return
 */
private FileObject getFileObject(Node node) {
    assert node != null;
    FileObject fileObj = node.getLookup().lookup(FileObject.class);
    if (fileObj != null && fileObj.isValid()) {
        return fileObj;
    }
    DataObject dataObj = node.getCookie(DataObject.class);
    if (dataObj == null) {
        return null;
    }
    fileObj = dataObj.getPrimaryFile();
    if (fileObj != null && fileObj.isValid()) {
        return fileObj;
    }
    return null;
}
Also used : DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject)

Example 3 with DataObject

use of org.openide.loaders.DataObject in project syncope by apache.

the class ResourceExplorerTopComponent method openMailEditor.

private void openMailEditor(final String name) throws IOException {
    String formatStr = (String) JOptionPane.showInputDialog(null, "Select File Format", "File format", JOptionPane.QUESTION_MESSAGE, null, PluginConstants.MAIL_TEMPLATE_FORMATS, MailTemplateFormat.TEXT.name());
    if (StringUtils.isNotBlank(formatStr)) {
        MailTemplateFormat format = MailTemplateFormat.valueOf(formatStr);
        String type = null;
        InputStream is = null;
        try {
            switch(format) {
                case HTML:
                    type = "html";
                    is = (InputStream) mailTemplateManagerService.getFormat(name, MailTemplateFormat.HTML);
                    break;
                case TEXT:
                    type = "txt";
                    is = (InputStream) mailTemplateManagerService.getFormat(name, MailTemplateFormat.TEXT);
                    break;
                default:
                    LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format));
                    break;
            }
        } catch (SyncopeClientException e) {
            LOG.log(Level.SEVERE, String.format("Unable to get [%s] mail template in [%s] format", name, format), e);
            if (ClientExceptionType.NotFound.equals(e.getType())) {
                LOG.log(Level.SEVERE, String.format("Report template in [%s] format not found, create an empty one", format));
            } else {
                JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] report template in [%s] format", name, format), "Connection Error", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception e) {
            LOG.log(Level.SEVERE, String.format("Unable to get [%s] mail template in [%s] format", name, format), e);
            JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] mail template in [%s] format", name, format), "Error", JOptionPane.ERROR_MESSAGE);
        }
        String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern);
        String mailTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Mail/";
        File mailTemplatesDir = new File(mailTemplatesDirName);
        if (!mailTemplatesDir.exists()) {
            mailTemplatesDir.mkdirs();
        }
        File file = new File(mailTemplatesDirName + name + "." + type);
        FileWriter fw = new FileWriter(file);
        fw.write(content);
        fw.flush();
        FileObject fob = FileUtil.toFileObject(file.getAbsoluteFile());
        fob.setAttribute("description", "TEXT");
        DataObject data = DataObject.find(fob);
        data.getLookup().lookup(OpenCookie.class).open();
        data.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent evt) {
                if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) {
                    // save item remotely
                    LOG.info(String.format("Saving Mail template [%s]", name));
                    saveContent();
                }
            }
        });
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) OpenCookie(org.openide.cookies.OpenCookie) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BadLocationException(javax.swing.text.BadLocationException) IOException(java.io.IOException) MailTemplateFormat(org.apache.syncope.common.lib.types.MailTemplateFormat) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 4 with DataObject

use of org.openide.loaders.DataObject in project syncope by apache.

the class ResourceExplorerTopComponent method openReportEditor.

private void openReportEditor(final String name) throws IOException {
    String formatStr = (String) JOptionPane.showInputDialog(null, "Select File Format", "File format", JOptionPane.QUESTION_MESSAGE, null, PluginConstants.REPORT_TEMPLATE_FORMATS, ReportTemplateFormat.FO.name());
    if (StringUtils.isNotBlank(formatStr)) {
        ReportTemplateFormat format = ReportTemplateFormat.valueOf(formatStr);
        InputStream is = null;
        try {
            switch(format) {
                case HTML:
                    is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.HTML);
                    break;
                case CSV:
                    is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.CSV);
                    break;
                case FO:
                    is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.FO);
                    break;
                default:
                    LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format));
                    break;
            }
        } catch (SyncopeClientException e) {
            LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), e);
            if (ClientExceptionType.NotFound.equals(e.getType())) {
                LOG.log(Level.SEVERE, String.format("Report template [%s] not found, create an empty one", name));
            } else {
                JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] report template in [%s] format", name, format), "Connection Error", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception e) {
            LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), e);
            JOptionPane.showMessageDialog(null, String.format("Unable to get [%s] report template in [%s] format", name, format), "Generic Error", JOptionPane.ERROR_MESSAGE);
        }
        String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern);
        String reportTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Report/";
        File reportTemplatesDir = new File(reportTemplatesDirName);
        if (!reportTemplatesDir.exists()) {
            reportTemplatesDir.mkdirs();
        }
        File file = new File(reportTemplatesDirName + name + "." + format.name().toLowerCase());
        FileWriter fw = new FileWriter(file);
        fw.write(content);
        fw.flush();
        FileObject fob = FileUtil.toFileObject(file.getAbsoluteFile());
        DataObject data = DataObject.find(fob);
        data.getLookup().lookup(OpenCookie.class).open();
        data.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent evt) {
                if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) {
                    // save item remotely
                    LOG.info(String.format("Saving Report template [%s]", name));
                    saveContent();
                }
            }
        });
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ReportTemplateFormat(org.apache.syncope.common.lib.types.ReportTemplateFormat) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) OpenCookie(org.openide.cookies.OpenCookie) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) BadLocationException(javax.swing.text.BadLocationException) IOException(java.io.IOException) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 5 with DataObject

use of org.openide.loaders.DataObject in project Universal-G-Code-Sender by winder.

the class EditGcodeFile method openFile.

/**
 * Open an Editor Window in the application, ensuring that only one editor
 * is ever opened at the same time.
 */
private void openFile(File f) {
    // Close any opened file.
    closeOpenFile();
    try {
        FileObject fo = FileUtil.toFileObject(backend.getGcodeFile());
        DataObject dOb = DataObject.find(fo);
        dOb.getLookup().lookup(OpenCookie.class).open();
        java.awt.EventQueue.invokeLater(() -> updateListener(true));
    } catch (DataObjectNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : DataObject(org.openide.loaders.DataObject) DataObjectNotFoundException(org.openide.loaders.DataObjectNotFoundException) FileObject(org.openide.filesystems.FileObject) OpenCookie(org.openide.cookies.OpenCookie)

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