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;
}
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;
}
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();
}
}
});
}
}
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();
}
}
});
}
}
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);
}
}
Aggregations