org.openide.cookies.OpenCookie Java Examples
The following examples show how to use
org.openide.cookies.OpenCookie.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GraphNode.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private GraphNode(final InputGraph graph, InstanceContent content) { super(Children.LEAF, new AbstractLookup(content)); this.graph = graph; this.setDisplayName(graph.getName()); content.add(graph); final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class); if (viewer != null) { // Action for opening the graph content.add(new OpenCookie() { public void open() { viewer.view(graph); } }); } // Action for removing a graph content.add(new RemoveCookie() { public void remove() { graph.getGroup().removeGraph(graph); } }); }
Example #2
Source File: NodeUtilsTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testReadOnlyLocalRepositoryFile() throws Exception { File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile(); File f = TestFileUtils.writeFile(new File(repo, "ant/ant/1.5.1/ant-1.5.1.jar.sha1"), "a50e3e050a6e78e0656edc183435b9773f53ce78"); FileObject rw = FileUtil.toFileObject(f); FileObject ro = NodeUtils.readOnlyLocalRepositoryFile(rw); assertNotSame(rw, ro); assertFalse(ro.canWrite()); assertNotNull(DataObject.find(ro).getLookup().lookup(OpenCookie.class)); f = TestFileUtils.writeFile(new File(repo, "ant/ant/1.5.1/ant-1.5.1.pom.sha1"), "0ffdb41f140a621beeec4dc81b3d3ecaee085d28"); rw = FileUtil.toFileObject(f); ro = NodeUtils.readOnlyLocalRepositoryFile(rw); assertNotSame(rw, ro); assertFalse(ro.canWrite()); assertNotNull(DataObject.find(ro).getLookup().lookup(OpenCookie.class)); assertSame(ro, NodeUtils.readOnlyLocalRepositoryFile(rw)); FileObject skip = FileUtil.toFileObject(new File(repo, "ant/ant/1.5.1")); assertNotNull(skip); assertSame(skip, NodeUtils.readOnlyLocalRepositoryFile(skip)); File stuff = TestFileUtils.writeFile(new File(getWorkDir(), "stuff"), "stuff"); skip = FileUtil.toFileObject(stuff); assertNotNull(skip); assertSame(skip, NodeUtils.readOnlyLocalRepositoryFile(skip)); Reference<?> r = new WeakReference<Object>(ro.getFileSystem()); ro = null; assertGC("can collect FS", r); }
Example #3
Source File: JSFConfigHyperlinkProvider.java From netbeans with Apache License 2.0 | 6 votes |
private void openInEditor(FileObject fObj){ if (fObj != null){ DataObject dobj = null; try{ dobj = DataObject.find(fObj); } catch (DataObjectNotFoundException e){ Exceptions.printStackTrace(e); return; } if (dobj != null){ Node.Cookie cookie = dobj.getCookie(OpenCookie.class); if (cookie != null) ((OpenCookie)cookie).open(); } } }
Example #4
Source File: FormDataObject.java From netbeans with Apache License 2.0 | 6 votes |
@Override public <T extends Cookie> T getCookie(Class<T> type) { T retValue; if (OpenCookie.class.equals(type) || EditCookie.class.equals(type)) { if (openEdit == null) openEdit = new OpenEdit(); retValue = type.cast(openEdit); } else if (!type.equals(Cookie.class) && type.isAssignableFrom(getFormEditorSupportClass())) { // Avoid calling synchronized getFormEditorSupport() when invoked from node lookup // initialization from cookies (asking for base Node.Cookie). retValue = (T) getFormEditorSupport(); } else { retValue = super.getCookie(type); } return retValue; }
Example #5
Source File: Tutorials.java From netbeans with Apache License 2.0 | 6 votes |
private Action extractAction( DataObject dob ) { OpenCookie oc = dob.getCookie( OpenCookie.class ); if( null != oc ) return new LinkAction( dob ); InstanceCookie.Of instCookie = dob.getCookie(InstanceCookie.Of.class); if( null != instCookie && instCookie.instanceOf( Action.class ) ) { try { Action res = (Action) instCookie.instanceCreate(); if( null != res ) { res.putValue(Action.NAME, dob.getNodeDelegate().getDisplayName() ); } return res; } catch( Exception e ) { Logger.getLogger(SampleProjectAction.class.getName()).log( Level.INFO, null, e ); } } return null; }
Example #6
Source File: ViewPomAction.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override protected void performAction(Node[] activatedNodes) { for (Node node : activatedNodes) { ArtifactData data = node.getLookup().lookup(ArtifactData.class); if(data!=null && data.getPomPath()!=null){ FileObject fo = FileUtil.toFileObject(new File(data.getPomPath())); if(fo!=null){ try { DataObject dob = DataObject.find(fo); OpenCookie open = dob.getLookup().lookup(OpenCookie.class); if(open!=null){ open.open(); } } catch (DataObjectNotFoundException ex) { } } } } }
Example #7
Source File: ActionProviderImpl.java From netbeans with Apache License 2.0 | 6 votes |
private static void open(FileObject file, int line) { LineCookie lc = file.getLookup().lookup(LineCookie.class); if (lc != null) { Line.Set ls = lc.getLineSet(); try { Line originalLine = ls.getOriginal(line); originalLine.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS); } catch (IndexOutOfBoundsException ex) { LOG.log(Level.FINE, null, ex); } } OpenCookie oc = file.getLookup().lookup(OpenCookie.class); if (oc != null) { oc.open(); } }
Example #8
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Opens a file in the editor area. * * @param file a File to open */ public static void openFile(File file) { FileObject fo = FileUtil.toFileObject(file); if (fo != null) { try { DataObject dao = DataObject.find(fo); final OpenCookie oc = dao.getLookup().lookup(OpenCookie.class); if (oc != null) { Mutex.EVENT.readAccess(new Runnable() { @Override public void run () { oc.open(); } }); } } catch (DataObjectNotFoundException e) { // nonexistent DO, do nothing } } }
Example #9
Source File: OpenSupport.java From netbeans with Apache License 2.0 | 6 votes |
/** Method that allows environment to find its * cloneable open support. * @return the support or null if the environment is not in valid * state and the CloneableOpenSupport cannot be found for associated * data object */ public CloneableOpenSupport findCloneableOpenSupport() { OpenCookie oc = getDataObject().getCookie(OpenCookie.class); if (oc != null && oc instanceof CloneableOpenSupport) { return (CloneableOpenSupport) oc; } EditCookie edc = getDataObject().getCookie(EditCookie.class); if (edc != null && edc instanceof CloneableOpenSupport) { return (CloneableOpenSupport) edc; } EditorCookie ec = getDataObject().getCookie(EditorCookie.class); if (ec != null && ec instanceof CloneableOpenSupport) { return (CloneableOpenSupport) ec; } return null; }
Example #10
Source File: StrutsConfigHyperlinkProvider.java From netbeans with Apache License 2.0 | 6 votes |
private void openInEditor(FileObject fObj){ if (fObj != null){ DataObject dobj = null; try{ dobj = DataObject.find(fObj); } catch (DataObjectNotFoundException e){ Exceptions.printStackTrace(e); return; } if (dobj != null){ Node.Cookie cookie = dobj.getCookie(OpenCookie.class); if (cookie != null) ((OpenCookie)cookie).open(); } } }
Example #11
Source File: GetStarted.java From netbeans with Apache License 2.0 | 6 votes |
private Action extractAction( DataObject dob ) { OpenCookie oc = dob.getCookie( OpenCookie.class ); if( null != oc ) return new LinkAction( dob ); InstanceCookie.Of instCookie = dob.getCookie(InstanceCookie.Of.class); if( null != instCookie && instCookie.instanceOf( Action.class ) ) { try { Action res = (Action) instCookie.instanceCreate(); if( null != res ) { res.putValue(Action.NAME, dob.getNodeDelegate().getDisplayName() ); } return res; } catch( Exception e ) { Logger.getLogger(SampleProjectAction.class.getName()).log( Level.INFO, null, e ); } } return null; }
Example #12
Source File: GsfUtilities.java From netbeans with Apache License 2.0 | 6 votes |
/** * Gets the CloneableEditorSupport for given FileObject * * @param fo A FileObject to get the CES for. * @return Instance of CloneableEditorSupport */ public static CloneableEditorSupport findCloneableEditorSupport(FileObject fo) { try { DataObject dob = DataObject.find(fo); Object obj = dob.getCookie(OpenCookie.class); if (obj instanceof CloneableEditorSupport) { return (CloneableEditorSupport)obj; } obj = dob.getCookie(org.openide.cookies.EditorCookie.class); if (obj instanceof CloneableEditorSupport) { return (CloneableEditorSupport)obj; } } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } return null; }
Example #13
Source File: GraphNode.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private GraphNode(final InputGraph graph, InstanceContent content) { super(Children.LEAF, new AbstractLookup(content)); this.graph = graph; this.setDisplayName(graph.getName()); content.add(graph); final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class); if (viewer != null) { // Action for opening the graph content.add(new OpenCookie() { public void open() { viewer.view(graph); } }); } // Action for removing a graph content.add(new RemoveCookie() { public void remove() { graph.getGroup().removeGraph(graph); } }); }
Example #14
Source File: OpenTaskAction.java From netbeans with Apache License 2.0 | 6 votes |
private boolean canOpenTask() { if( null != Accessor.getDefaultAction( task ) ) return true; URL url = Accessor.getURL( task ); if( null != url ) return true; FileObject fo = Accessor.getFile(task); if( null == fo ) return false; DataObject dob = null; try { dob = DataObject.find( fo ); } catch( DataObjectNotFoundException donfE ) { return false; } if( Accessor.getLine( task ) > 0 ) { return null != dob.getCookie( LineCookie.class ); } return null != dob.getCookie( OpenCookie.class ) || null != dob.getCookie( EditCookie.class ) || null != dob.getCookie( ViewCookie.class ); }
Example #15
Source File: DataNodeTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override public <T extends Node.Cookie> T getCookie(Class<T> clazz) { if (clazz.isAssignableFrom(OpenCookie.class)) { return clazz.cast(new OpenCookie () { public void open() { } }); } return super.getCookie(clazz); }
Example #16
Source File: NavigationCaseEdge.java From netbeans with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public <T extends Cookie> T getCookie(Class<T> type) { if( type.equals(SaveCookie.class)) { pc.serializeNodeLocations(); return pc.getConfigDataObject().getCookie(type); } else if ( type.equals(OpenCookie.class)){ return (T) new OpenCookie() { public void open() { pc.openNavigationCase(edge); } }; } return null; }
Example #17
Source File: JSFConfigHyperlinkProvider.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({ "lbl.goto.source.not.found=Source file for {0} not found.", "lbl.managed.bean.not.found=Managed bean {0} not found." }) @Override public void run(CompilationController cc) throws Exception { cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); Elements elements = cc.getElements(); TypeElement element = elements.getTypeElement(fqn.trim()); if (element != null) { elementFound.set(true); ElementHandle el = ElementHandle.create(element); FileObject fo = SourceUtils.getFile(el, cpi); if (fo == null) { StatusDisplayer.getDefault().setStatusText(Bundle.lbl_managed_bean_not_found(fqn)); Toolkit.getDefaultToolkit().beep(); return; } // Not a regular Java data object (may be a multi-view data object), open it first DataObject od = DataObject.find(fo); if (!"org.netbeans.modules.java.JavaDataObject".equals(od.getClass().getName())) { //NOI18N OpenCookie oc = od.getCookie(org.openide.cookies.OpenCookie.class); oc.open(); } if (!ElementOpen.open(fo, el)) { StatusDisplayer.getDefault().setStatusText(Bundle.lbl_goto_source_not_found(fqn)); Toolkit.getDefaultToolkit().beep(); } } else if (!SourceUtils.isScanInProgress()) { StatusDisplayer.getDefault().setStatusText(Bundle.lbl_managed_bean_not_found(fqn)); Toolkit.getDefaultToolkit().beep(); } }
Example #18
Source File: DefaultDataObjectHasOpenTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testComponentCanBeSerializedEvenItIsBinary() throws Exception { // make sure it has the cookie OpenCookie open = obj.getCookie(OpenCookie.class); DD.toReturn = DialogDescriptor.OK_OPTION; open.open(); open = null; doComponentCanBeSerialized("\u0003\u0001\u0000"); }
Example #19
Source File: SimpleDESTest.java From netbeans with Apache License 2.0 | 5 votes |
public SO (FileObject fo) throws org.openide.loaders.DataObjectExistsException { super (fo, SL.getLoader(SL.class)); cookie = RUNNING.createEditorCookie(this); if (fo.getNameExt().indexOf ("MaskEdit") == -1) { getCookieSet ().add (cookie); } else { getCookieSet ().add (new Class[] { OpenCookie.class, org.openide.cookies.CloseCookie.class, EditorCookie.class, org.openide.cookies.PrintCookie.class }, this); } }
Example #20
Source File: DataEditorSupportTest.java From netbeans with Apache License 2.0 | 5 votes |
DES support () throws Exception { DataObject tmpObj = DataObject.find (fileObject); assertEquals ("My object was created", MyDataObject.class, tmpObj.getClass ()); Object cookie = tmpObj.getCookie (org.openide.cookies.OpenCookie.class); assertNotNull ("Our object has this cookie", cookie); assertEquals ("It is my cookie", DES.class, cookie.getClass ()); return (DES)cookie; }
Example #21
Source File: FXMLEditAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { DataObject dobj = context.lookup(DataObject.class); OpenCookie oc = dobj.getCookie(OpenCookie.class); if (oc != null) { oc.open(); } }
Example #22
Source File: DataEditorSupportSaveAsTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override public <T extends Cookie> T getCookie(Class<T> type) { if( type.equals( OpenCookie.class) ) { OpenCookie oc = new OpenCookie() { public void open() { openCookieCalls++; } }; return type.cast(oc); } return super.getCookie(type); }
Example #23
Source File: MultiDataObjectVersion1Test.java From netbeans with Apache License 2.0 | 5 votes |
public void testEditorInLookup() throws Exception { assertTrue(this.one instanceof SimpleObject); SimpleObject s = (SimpleObject)this.one; LineCookie line = s.getLookup().lookup(LineCookie.class); assertNotNull("Line cookie is there", line); assertEquals("Edit cookie", line, s.getLookup().lookup(EditCookie.class)); assertEquals("Editor cookie", line, s.getLookup().lookup(EditorCookie.class)); assertEquals("Editor objservable cookie", line, s.getLookup().lookup(EditorCookie.Observable.class)); assertEquals("SaveAsCapable", line, s.getLookup().lookup(SaveAsCapable.class)); assertEquals("Open cookie", line, s.getLookup().lookup(OpenCookie.class)); assertEquals("Close cookie", line, s.getLookup().lookup(CloseCookie.class)); assertEquals("Print cookie", line, s.getLookup().lookup(PrintCookie.class)); }
Example #24
Source File: MultiDataObjectTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testAdditionsToCookieSetAreVisibleInLookup() throws Exception { assertTrue(this.one instanceof SimpleObject); SimpleObject s = (SimpleObject)this.one; class Open implements OpenCookie { public void open() { } } Open openCookie = new Open(); s.getCookieSet().add(openCookie); assertSame("Cookie is in the lookup", openCookie, one.getLookup().lookup(OpenCookie.class)); }
Example #25
Source File: DefaultDataObjectHasOpenTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testBinaryFilesQuestionContainsOpenActions() throws Exception { EditorCookie c = tryToOpen("\u0003\u0001\u0000"); assertNull(c); DD.toReturn = DialogDescriptor.CLOSED_OPTION; OpenCookie open = obj.getCookie(OpenCookie.class); open.open(); assertNotNull("There was a query", DD.options); assertEquals("Two options", 2, DD.options.length); assertEquals(DialogDescriptor.OK_OPTION, DD.options[0]); assertEquals(DialogDescriptor.CANCEL_OPTION, DD.options[1]); DD.options = null; DD.toReturn = DialogDescriptor.OK_OPTION; open.open(); assertNotNull("There was a query", DD.options); assertEquals("Still 2 options", 2, DD.options.length); assertEquals(DialogDescriptor.OK_OPTION, DD.options[0]); assertEquals(DialogDescriptor.CANCEL_OPTION, DD.options[1]); c = obj.getCookie(EditorCookie.class); assertNotNull("Editor cookie created", c); doRegularCheck(c); }
Example #26
Source File: PeterZMoveTest.java From netbeans with Apache License 2.0 | 5 votes |
DES support () throws Exception { DataObject obj = DataObject.find (fileObject); assertEquals ("My object was created", MyDataObject.class, obj.getClass ()); Object cookie = obj.getCookie (org.openide.cookies.OpenCookie.class); assertNotNull ("Our object has this cookie", cookie); assertEquals ("It is my cookie", DES.class, cookie.getClass ()); return (DES)cookie; }
Example #27
Source File: GLFFilesCustomEditor.java From netbeans with Apache License 2.0 | 5 votes |
private void bEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bEditActionPerformed String mimeType = (String) lFiles.getSelectedValue (); if (mimeType == null) return; FileObject fileObject = Repository.getDefault ().getDefaultFileSystem ().findResource ("Editors/" + mimeType + "/language.nbs"); try { DataObject dataObject = DataObject.find (fileObject); OpenCookie openCookie = dataObject.getCookie (OpenCookie.class); openCookie.open (); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace (ex); } }
Example #28
Source File: DataEditorReadOnlyTest.java From netbeans with Apache License 2.0 | 5 votes |
DES support () throws Exception { DataObject tmpObj = DataObject.find (fileObject); assertEquals ("My object was created", MyDataObject.class, tmpObj.getClass ()); Object cookie = tmpObj.getCookie (org.openide.cookies.OpenCookie.class); assertNotNull ("Our object has this cookie", cookie); assertEquals ("It is my cookie", DES.class, cookie.getClass ()); return (DES)cookie; }
Example #29
Source File: FXMLOpenAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean open(Lookup context) { DataObject dobj = context.lookup(DataObject.class); OpenCookie oc = dobj.getCookie(OpenCookie.class); if (oc != null) { oc.open(); return true; } return false; }
Example #30
Source File: DefaultDataObject.java From netbeans with Apache License 2.0 | 5 votes |
/** Getter for cookie. * @param force if true, there are no checks for content of the file */ final <T extends Node.Cookie> T getCookie(Class<T> c, boolean force) { if (c == OpenCookie.class) { return c.cast(this); } T cook = super.getCookie (c); if (cook != null) { return cook; } fixCookieSet(c, force); return getCookieSet ().getCookie(c); }