private synchronized void updateCurrentFiles() { Set<FileObject> newCurrentFiles = new HashSet<FileObject>(); newCurrentFiles.addAll(fileObjectResult.allInstances()); for (DataObject d : dataObjectResult.allInstances()) { newCurrentFiles.add(d.getPrimaryFile()); } for (Node n : nodeResult.allInstances()) { newCurrentFiles.addAll(n.getLookup().lookupAll(FileObject.class)); for (DataObject d : n.getLookup().lookupAll(DataObject.class)) { newCurrentFiles.add(d.getPrimaryFile()); } } List<FileObject> newCurrentFilesFiltered = OpenedEditors.filterSupportedMIMETypes( new LinkedList<FileObject>(newCurrentFiles), supportedMimeTypes); if (!currentFiles.equals(newCurrentFilesFiltered)) { currentFiles = newCurrentFilesFiltered; lookupContentChanged(); } }
public ListIterator<Node> getRemaining(Node current) { Vector<Node> v = new Vector<Node>(); for (Node n : list.subList(indexOf(current), list.size())) { v.add(n.getLookup().lookup(ModelComponentNode.class)); } return (v.listIterator()); }
private void actionPerformed(Node node) { int id = node.getLookup().lookup(Integer.class); Exception ex = node.getLookup().lookup(Exception.class); if (isInModalDialog()) { showDialog(ex); } else { showTopComponent(id, ex); } }
@Override public boolean isSupported(Node node) { if (node == null) { return false; } Collection<? extends MarkupSource> sources = node.getLookup().lookupAll(MarkupSource.class); HighlightLookup highlight = node.getLookup().lookup(HighlightLookup.class); return !sources.isEmpty() || highlight != null || solrHasContent(node); }
public RootNode(Node node, TitanPlatformProject project) throws DataObjectNotFoundException { super( node, new FilterNode.Children(node), new ProxyLookup(new Lookup[] {Lookups.singleton(project), node.getLookup()})); this.project = project; }
/* (non-Javadoc) * @see org.openide.util.actions.NodeAction#enable(org.openide.nodes.Node[]) */ @Override protected boolean enable(Node[] nodes) { // TODO Solve friend dependency issues to maven module and try again :-/ // boolean isMvn = false; if (null != nodes) { for (Node currentnode : nodes) { DataObject dObj = currentnode.getLookup().lookup(DataObject.class); if (null != dObj) { determineSelectedClass(dObj); } Project pro = Te2mWizardBase.findProjectThatOwnsNode(currentnode); /* if( null!=pro && pro instanceof NbMavenProject ) { isMvn=true; NbMavenProject mvnPro = (NbMavenProject)pro; System.out.println("Works :-)"); } */ } } /* if (isMvn) { return isEnabled(); } return false; */ return isEnabled(); }
/** * Creates a new instance of CookieProxyLookup. * * @param lookups the Lookup instances to which we proxy. * @param delegate the Node delegate from which cookies come. */ public SourceCookieProxyLookup(Lookup[] lookups, Node delegate) { super(); this.lookups = lookups; this.delegate = delegate; setLookups( new Lookup[] {new ProxyLookup(lookups), delegate.getLookup(), Lookups.singleton(delegate)}); }
public synchronized void propertyChange(PropertyChangeEvent event) { if (propertyChanging) { // Avoid an infinite loop whereby changing the lookup contents // causes the activated nodes to change, which calls us again. return; } propertyChanging = true; try { Node[] newNodes = (Node[]) event.getNewValue(); if (newNodes == null || newNodes.length == 0) { setLookups( new Lookup[] { new ProxyLookup(lookups), new NoNodeLookup(delegate.getLookup()), Lookups.singleton(delegate) }); } else { Lookup[] newNodeLookups = new Lookup[newNodes.length]; for (int i = 0; i < newNodes.length; i++) { newNodeLookups[i] = new NoNodeLookup(newNodes[i].getLookup()); } setLookups( new Lookup[] { new ProxyLookup(lookups), new ProxyLookup(newNodeLookups), Lookups.fixed((Object[]) newNodes) }); } } finally { propertyChanging = false; } }
/* (non-Javadoc) * @see org.openide.util.actions.NodeAction#performAction(org.openide.nodes.Node[]) */ @Override protected void performAction(Node[] nodes) { // context. if (null != nodes) { for (Node currentnode : nodes) { DataObject dObj = currentnode.getLookup().lookup(DataObject.class); // Project pRoot = currentnode.getLookup().lookup(Project.class); Project pRoot = Te2mWizardBase.findProjectThatOwnsNode(currentnode); if (null != dObj) { determineSelectedClass(dObj); FileObject fo = dObj.getPrimaryFile(); JavaSource jsource = JavaSource.forFileObject(fo); if (jsource == null) { StatusDisplayer.getDefault().setStatusText("Not a Java file: " + fo.getPath()); } else { StatusDisplayer.getDefault().setStatusText("Hurray! A Java file: " + fo.getPath()); executeWizard(currentnode); } } } } }
private Node getNextMeaningfullNode() { if (comp.nodesForNext == null) { comp.nodesForNext = new LinkedList<Node>(); comp.nodesForNext.add(comp.getExplorerManager().getRootContext()); } List<Node> nodesForNext = comp.nodesForNext; while (!nodesForNext.isEmpty()) { Node top = nodesForNext.remove(0); if (top.getChildren() != Children.LEAF) { nodesForNext.addAll(0, Arrays.asList(top.getChildren().getNodes(true))); continue; } ErrorDescription ed = top.getLookup().lookup(ErrorDescription.class); if (ed != null) { Node[] selected = comp.getExplorerManager().getSelectedNodes(); if (selected.length == 1 && selected[0] == top) { addToSeenNodes(top); continue; } return top; } } return null; }
@Override public boolean isSupported(Node node) { if (node == null) { return false; } AbstractFile file = node.getLookup().lookup(AbstractFile.class); if (file == null) { return false; } if (file.getSize() == 0) { return false; } String name = file.getName().toLowerCase(); if (imagePanelInited) { if (containsExt(name, imageExtensions)) { return true; } else if (Utilities.isJpegFileHeader(file)) { return true; } // for gstreamer formats, check if initialized first, then // support audio formats, and video formats } if (videoPanelInited && videoPanel.isInited()) { if (containsExt(name, AUDIO_EXTENSIONS) || (containsExt(name, videoExtensions))) { return true; } } return false; }
/** Refreshes changed content nodes */ private void refreshDataSourceTree() { Node selectedNode = getSelectedNode(); final String[] selectedPath = NodeOp.createPath(selectedNode, em.getRootContext()); Children rootChildren = em.getRootContext().getChildren(); Node dataSourcesFilterNode = rootChildren.findChild(DataSourcesNode.NAME); if (dataSourcesFilterNode == null) { logger.log( Level.SEVERE, "Cannot find data sources filter node, won't refresh the content tree"); // NON-NLS return; } OriginalNode imagesNodeOrig = dataSourcesFilterNode.getLookup().lookup(OriginalNode.class); if (imagesNodeOrig == null) { logger.log( Level.SEVERE, "Cannot find data sources node, won't refresh the content tree"); // NON-NLS return; } Node imagesNode = imagesNodeOrig.getNode(); RootContentChildren contentRootChildren = (RootContentChildren) imagesNode.getChildren(); contentRootChildren.refreshContentKeys(); // final TreeView tree = getTree(); // tree.expandNode(imagesNode); setSelectedNode(selectedPath, DataSourcesNode.NAME); }
@Override public boolean isPreferred(Node node, boolean isSupported) { BlackboardArtifact art = node.getLookup().lookup(BlackboardArtifact.class); return isSupported && (art == null || art.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()); }
@Override public void resultChanged(LookupEvent le) { Collection<? extends Person> p = personResult.allInstances(); if (p.size() == 1) { Person currentPerson = p.iterator().next(); for (Node node : em.getRootContext().getChildren().getNodes()) { if (node.getLookup().lookup(Synchronizable.class).getPerson() == currentPerson) { try { em.setSelectedNodes(new Node[] {node}); } catch (PropertyVetoException ex) { Exceptions.printStackTrace(ex); } } } } }
@Override public void setNode(Node selectedNode) { if (selectedNode != null) { Lookup lookup = selectedNode.getLookup(); Content content = lookup.lookup(Content.class); if (content != null) { try { this.setDataView(content.getAllArtifacts(), 1); } catch (TskException ex) { logger.log(Level.WARNING, "Couldn't get artifacts: ", ex); } return; } } this.setDataView(new ArrayList<BlackboardArtifact>(), 1); }
/** * Get extracted content for a node from Solr * * @param cNode a node that has extracted content in Solr (check with solrHasContent(ContentNode)) * @return the extracted content * @throws SolrServerException if something goes wrong */ private String getSolrContent(Node node, int currentPage, boolean hasChunks) throws SolrServerException { Content contentObj = node.getLookup().lookup(Content.class); final Server solrServer = KeywordSearch.getServer(); int chunkId = 0; if (hasChunks) { chunkId = currentPage; } String content = null; try { content = (String) solrServer.getSolrContent(contentObj, chunkId); } catch (NoOpenCoreException ex) { logger.log(Level.WARNING, "Couldn't get text content.", ex); return ""; } return content; }
/** * Check if Solr has extracted content for a given node * * @param node * @return true if Solr has content, else false */ private boolean solrHasContent(Node node) { Content content = node.getLookup().lookup(Content.class); if (content == null) { return false; } final Server solrServer = KeywordSearch.getServer(); final long contentID = content.getId(); try { return solrServer.queryIsIndexed(contentID); } catch (NoOpenCoreException ex) { logger.log(Level.WARNING, "Couldn't determine whether content is supported.", ex); return false; } catch (SolrServerException ex) { logger.log(Level.WARNING, "Couldn't determine whether content is supported.", ex); return false; } }
@Override public int isPreferred(Node node, boolean isSupported) { if (isSupported) { // special case, check if deleted video, then do not make it preferred AbstractFile file = node.getLookup().lookup(AbstractFile.class); if (file == null) { return 0; } String name = file.getName().toLowerCase(); boolean deleted = file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC); if (containsExt(name, videoExtensions) && deleted) { return 0; } else { return 7; } } else { return 0; } }
@Override public void setNode(Node selectedNode) { try { if (selectedNode == null) { resetComponent(); return; } AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class); if (file == null) { resetComponent(); return; } if (file.equals(lastFile)) { return; // prevent from loading twice if setNode() called mult. times } lastFile = file; final Dimension dims = DataContentViewerMedia.this.getSize(); logger.info("setting node on media viewer"); if (imagePanelInited && containsExt(file.getName(), imageExtensions)) { imagePanel.showImageFx(file, dims); this.switchPanels(false); } else if (imagePanelInited && Utilities.isJpegFileHeader(file)) { imagePanel.showImageFx(file, dims); this.switchPanels(false); } else if (videoPanelInited && (containsExt(file.getName(), videoExtensions) || containsExt(file.getName(), AUDIO_EXTENSIONS))) { videoPanel.setupVideo(file, dims); switchPanels(true); } } catch (Exception e) { logger.log(Level.SEVERE, "Exception while setting node", e); } }
public void actionPerformed(ActionEvent e) { Node node = getNextMeaningfullNode(); if (node == null) { // should not happen fireEnabledChanged(); return; } OpenCookie oc = node.getLookup().lookup(OpenCookie.class); assert oc != null; addToSeenNodes(node); try { comp.getExplorerManager().setSelectedNodes(new Node[] {node}); } catch (PropertyVetoException ex) { Exceptions.printStackTrace(ex); } oc.open(); fireEnabledChanged(); }
// move into editor? private ContainerProxy findComponentsAndParent(List<ComponentProxy> components) { Node[] nodes = em.getSelectedNodes(); ContainerProxy parent = null; for (Node node : nodes) { ComponentProxy cmp = node.getLookup().lookup(ComponentProxy.class); if (cmp != null) { ContainerProxy p = cmp.getParent(); if (p == null || cmp == editor.getContainer()) { parent = null; break; } if (parent == null) { parent = p; } else if (parent != p) { parent = null; break; } if (components != null) { components.add(cmp); } } } return parent; }
private boolean accept(Node node) { Person p = node.getLookup().lookup(Person.class); // make case insensitive return (p == null || p.toString().toLowerCase().contains(searchString)); }
/** the constructor */ DirectoryTreeFilterNode(Node arg, boolean createChildren) { super( arg, DirectoryTreeFilterChildren.createInstance(arg, createChildren), new ProxyLookup(Lookups.singleton(new OriginalNode(arg)), arg.getLookup())); }
/** * @return <code>true</code> if * <ul> * <li>the node contains a project in its lookup and * <li>the project contains at least one CVS versioned source group * </ul> * otherwise <code>false</code>. * @param checkStatus if set to true, cache.getStatus is called and can take significant amount of * time */ public static boolean isVersionedProject(Node node, boolean checkStatus) { Lookup lookup = node.getLookup(); Project project = lookup.lookup(Project.class); return isVersionedProject(project, checkStatus); }
public static void overwriteFile(Node srcNode, Node destNode) throws IOException { DataObject srcDO = srcNode.getLookup().lookup(DataObject.class); FileObject srcFO = srcDO.getPrimaryFile(); DataObject destDO = destNode.getLookup().lookup(DataObject.class); FileObject destFO = destDO.getPrimaryFile(); // To avoid any confusion, save modified source first. if (srcDO.isModified()) { NotifyDescriptor d = new NotifyDescriptor.Confirmation( NbBundle.getMessage( FileNodeUtil.class, "MSG_SaveModifiedSource", srcFO.getNameExt()), // NOI18N NbBundle.getMessage(FileNodeUtil.class, "TTL_SaveModifiedSource"), // NOI18N NotifyDescriptor.OK_CANCEL_OPTION); if (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.OK_OPTION) { EditorCookie srcEditorCookie = srcDO.getCookie(EditorCookie.class); srcEditorCookie.saveDocument(); } } // // Alternatively, we could use the in-memory copy of the source file // EditorCookie srcEditorCookie = // (EditorCookie) srcDO.getCookie(EditorCookie.class); // Document srcDocument = srcEditorCookie.getDocument(); // if (srcDocument == null) { // Task loadTask = srcEditorCookie.prepareDocument(); // new RequestProcessor().post(loadTask); // // loadTask.waitFinished(); // srcDocument = srcEditorCookie.getDocument(); // } // String srcText = srcDocument.getText(0, srcDocument.getLength()); // From now on, we will only be using the on-disk copy of the source file. if (destDO.isModified()) { NotifyDescriptor d = new NotifyDescriptor.Confirmation( NbBundle.getMessage( FileNodeUtil.class, "MSG_OverwriteModifiedDestination", destFO.getNameExt()), // NOI18N NbBundle.getMessage(FileNodeUtil.class, "TTL_OverwriteModifiedDestination"), // NOI18N NotifyDescriptor.OK_CANCEL_OPTION); if (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.CANCEL_OPTION) { return; } EditorCookie destEditorCookie = destDO.getCookie(EditorCookie.class); InputStream inputStream = null; try { inputStream = srcFO.getInputStream(); String srcText = getInputStreamContents(inputStream); Document outputDocument = destEditorCookie.getDocument(); try { outputDocument.remove(0, outputDocument.getLength()); } catch (java.lang.Exception e) { // Ignore exception here on purpose. // One of the listener from xml module throws NPE: // at // org.netbeans.modules.xml.text.completion.GrammarManager.isGuarded(GrammarManager.java:170) // at // org.netbeans.modules.xml.text.completion.GrammarManager.removeUpdate(GrammarManager.java:140) // at // org.netbeans.lib.editor.util.swing.PriorityDocumentListenerList.removeUpdate(PriorityDocumentListenerList.java:63) // at javax.swing.text.AbstractDocument.fireRemoveUpdate(AbstractDocument.java:242) // at org.netbeans.editor.BaseDocument.fireRemoveUpdate(BaseDocument.java:1305) // at org.netbeans.editor.BaseDocument.remove(BaseDocument.java:737) } outputDocument.insertString(0, srcText, null); destEditorCookie.saveDocument(); } catch (BadLocationException e) { e.printStackTrace(); throw new IOException(e.getMessage()); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (Exception e) {; } } } else { FileLock lock = destFO.lock(); InputStream inputStream = null; OutputStream outputStream = null; try { outputStream = destFO.getOutputStream(lock); inputStream = srcFO.getInputStream(); FileUtil.copy(inputStream, outputStream); } finally { try { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } lock.releaseLock(); } catch (Exception e) {; } } } }
/** * @param node * @param keys * @throws IntrospectionException */ public DirObjectNode(Node node, DirectoryObject object) { super( Children.LEAF, new ProxyLookup(new Lookup[] {Lookups.fixed(new Object[] {object}), node.getLookup()})); }
@Override public Lookup getSelectedClient() { return selectedMethod.getLookup(); }
@Override public void setNode(final Node selectedNode) { // TODO why setNode() is called twice for the same node each time // to clear the viewer if (selectedNode == null) { currentNode = null; resetComponent(); return; } this.currentNode = selectedNode; // sources are custom markup from the node (if available) and default // markup is fetched from solr List<MarkupSource> sources = new ArrayList<MarkupSource>(); // add additional registered sources for this node sources.addAll(selectedNode.getLookup().lookupAll(MarkupSource.class)); if (solrHasContent(selectedNode)) { Content content = selectedNode.getLookup().lookup(Content.class); if (content == null) { return; } // add to page tracking if not there yet final long contentID = content.getId(); MarkupSource newSource = new MarkupSource() { private boolean inited = false; private int numPages = 0; private int currentPage = 0; private boolean hasChunks = false; @Override public int getCurrentPage() { return this.currentPage; } @Override public boolean hasNextPage() { return currentPage < numPages; } @Override public boolean hasPreviousPage() { return currentPage > 1; } @Override public int nextPage() { if (!hasNextPage()) { throw new IllegalStateException("No next page."); } ++currentPage; return currentPage; } @Override public int previousPage() { if (!hasPreviousPage()) { throw new IllegalStateException("No previous page."); } --currentPage; return currentPage; } @Override public boolean hasNextItem() { throw new UnsupportedOperationException("Not supported, not a searchable source."); } @Override public boolean hasPreviousItem() { throw new UnsupportedOperationException("Not supported, not a searchable source."); } @Override public int nextItem() { throw new UnsupportedOperationException("Not supported, not a searchable source."); } @Override public int previousItem() { throw new UnsupportedOperationException("Not supported, not a searchable source."); } @Override public int currentItem() { throw new UnsupportedOperationException("Not supported, not a searchable source."); } @Override public String getMarkup() { try { String content = StringEscapeUtils.escapeHtml( getSolrContent(selectedNode, currentPage, hasChunks)); return "<pre>" + content.trim() + "</pre>"; } catch (SolrServerException ex) { logger.log(Level.WARNING, "Couldn't get extracted content.", ex); return ""; } } @Override public String toString() { return "Extracted Content"; } @Override public boolean isSearchable() { return false; } @Override public String getAnchorPrefix() { return ""; } @Override public int getNumberHits() { return 0; } @Override public LinkedHashMap<Integer, Integer> getHitsPages() { return null; } @Override public int getNumberPages() { if (inited) { return this.numPages; } final Server solrServer = KeywordSearch.getServer(); try { numPages = solrServer.queryNumFileChunks(contentID); if (numPages == 0) { numPages = 1; hasChunks = false; } else { hasChunks = true; } inited = true; } catch (SolrServerException ex) { logger.log(Level.WARNING, "Could not get number of chunks: ", ex); } catch (NoOpenCoreException ex) { logger.log(Level.WARNING, "Could not get number of chunks: ", ex); } return numPages; } }; currentSource = newSource; sources.add(newSource); // init pages final int totalPages = currentSource.getNumberPages(); int currentPage = currentSource.getCurrentPage(); if (currentPage == 0 && currentSource.hasNextPage()) { currentSource.nextPage(); } updatePageControls(); } // first source will be the default displayed setPanel(sources); // If node has been selected before, return to the previous position scrollToCurrentHit(); }