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