org.openide.cookies.EditCookie Java Examples
The following examples show how to use
org.openide.cookies.EditCookie.
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: XSLWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
/** * This is where, the schema gets instantiated from the template. */ public Set instantiate (TemplateWizard wizard) throws IOException { FileObject dir = Templates.getTargetFolder( wizard ); DataFolder df = DataFolder.findFolder( dir ); FileObject template = Templates.getTemplate( wizard ); DataObject dTemplate = DataObject.find( template ); DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard)); if (dobj == null) return Collections.emptySet(); encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile()); if(!EncodingUtil.isValidEncoding(encoding)) encoding = "UTF-8"; //NOI18N EditCookie edit = dobj.getCookie(EditCookie.class); if (edit != null) { EditorCookie editorCookie = dobj.getCookie(EditorCookie.class); Document doc = (Document)editorCookie.openDocument(); fixEncoding(doc, encoding); SaveCookie save = dobj.getCookie(SaveCookie.class); if (save!=null) save.save(); } return Collections.singleton(dobj.getPrimaryFile()); }
Example #2
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 #3
Source File: NoMVCLookupTest.java From netbeans with Apache License 2.0 | 6 votes |
private void createAndOpen(L l, String fileName) throws IOException, InterruptedException { // 1. create a file File f = new File(getWorkDir(), fileName + "-" + System.currentTimeMillis() + ".txt"); f.createNewFile(); FileObject fo = FileUtil.toFileObject(f); DataObject data = DataObject.find(fo); l.init(); // 2. open and ... EditCookie ec1 = data.getCookie(EditCookie.class); ec1.edit(); // 3. ... wait for the PROP_TC_OPENED event long t = System.currentTimeMillis(); while((!l.opened || !l.dataObjectFoundInLookup) && System.currentTimeMillis() - t < TIMEOUT) { Thread.sleep(200); } }
Example #4
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 #5
Source File: OpenSupport.java From netbeans with Apache License 2.0 | 6 votes |
public Object readResolve () { DataObject obj = entry.getDataObject (); OpenSupport os = null; OpenCookie oc = obj.getCookie(OpenCookie.class); if (oc != null && oc instanceof OpenSupport) { os = (OpenSupport) oc; } else { EditCookie edc = obj.getCookie(EditCookie.class); if (edc != null && edc instanceof OpenSupport) { os = (OpenSupport) edc; } else { EditorCookie ec = obj.getCookie(EditorCookie.class); if (ec != null && ec instanceof OpenSupport) { os = (OpenSupport) ec; } } } if (os == null) { // problem! no replace!? return this; } // use the editor support's CloneableTopComponent.Ref return os.allEditors (); }
Example #6
Source File: JAXBWizardOpenXSDIntoEditorAction.java From netbeans with Apache License 2.0 | 6 votes |
protected void performAction(Node[] nodes) { Node node = nodes[ 0 ]; FileObject fo = node.getLookup().lookup(FileObject.class ); try { if ( fo != null ) { DataObject dataObject = DataObject.find( fo ); if ( dataObject != null ) { EditCookie ec = dataObject.getCookie(EditCookie.class ); if ( ec != null ) { ec.edit(); } } } } catch ( DataObjectNotFoundException donfe ) { donfe.printStackTrace(); } }
Example #7
Source File: HyperlinkProviderImpl.java From netbeans with Apache License 2.0 | 6 votes |
public static void openAtSource(InputLocation location) { InputSource source = location.getSource(); if (source != null && source.getLocation() != null) { FileObject fobj = FileUtilities.convertStringToFileObject(source.getLocation()); if (fobj != null) { try { DataObject dobj = DataObject.find(NodeUtils.readOnlyLocalRepositoryFile(fobj)); EditCookie edit = dobj.getLookup().lookup(EditCookie.class); if (edit != null) { edit.edit(); } LineCookie lc = dobj.getLookup().lookup(LineCookie.class); lc.getLineSet().getOriginal(location.getLineNumber() - 1).show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS, location.getColumnNumber() - 1); } catch (DataObjectNotFoundException ex) { LOG.log(Level.FINE, "dataobject not found", ex); } } } }
Example #8
Source File: ModelUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Opens a pom file at location defined in InputLocation parameter * @since 2.77 * @param location */ public static void openAtSource(InputLocation location) { InputSource source = location.getSource(); if (source != null && source.getLocation() != null) { FileObject fobj = FileUtilities.convertStringToFileObject(source.getLocation()); if (fobj != null) { try { DataObject dobj = DataObject.find(NodeUtils.readOnlyLocalRepositoryFile(fobj)); EditCookie edit = dobj.getLookup().lookup(EditCookie.class); if (edit != null) { edit.edit(); } LineCookie lc = dobj.getLookup().lookup(LineCookie.class); lc.getLineSet().getOriginal(location.getLineNumber() - 1).show(Line.ShowOpenType.REUSE, Line.ShowVisibilityType.FOCUS, location.getColumnNumber() - 1); } catch (DataObjectNotFoundException ex) { LOG.log(Level.FINE, "dataobject not found", ex); } } } }
Example #9
Source File: DataObjectSaveAsTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testSaveAsWorksFineForDefaultDataObjects() throws Exception { FileUtil.createData(FileUtil.getConfigRoot(), "someFile.unknownExtension"); DataObject obj = DataObject.find(FileUtil.getConfigFile("someFile.unknownExtension")); assertEquals(DefaultDataObject.class, obj.getClass()); //this is ok because save as works for opened editors only so when the dataobject //is opened its editor support with saveas impl will be initialized already by then assertNotNull( obj.getLookup().lookup(EditCookie.class) ); assertNotNull( obj.getLookup().lookup(SaveAsCapable.class) ); sfs.clear(); DataObject newDob = obj.copyRename( obj.getFolder(), "newName", "newExt" ); assertNotNull( "object created", newDob ); assertEquals(DefaultDataObject.class, newDob.getClass()); FileObject fo = newDob.getPrimaryFile(); assertEquals( "newName", fo.getName() ); assertEquals( "newExt", fo.getExt() ); sfs.assertEvent(obj1, 1, "fileDataCreated"); }
Example #10
Source File: ManifestHyperlinkProvider.java From netbeans with Apache License 2.0 | 6 votes |
private EditCookie getEditorCookie(Document doc, int offset) { TokenHierarchy<?> th = TokenHierarchy.get(doc); TokenSequence ts = th.tokenSequence(Language.find("text/x-manifest")); if (ts == null) return null; ts.move(offset); if (!ts.moveNext()) return null; Token t = ts.token(); FileObject fo = getFileObject(doc); String name = t.toString(); FileObject props = findFile(fo, name); if (props != null) { try { DataObject dobj = DataObject.find(props); return dobj.getLookup().lookup(EditCookie.class); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } return null; }
Example #11
Source File: JaxWsClientNode.java From netbeans with Apache License 2.0 | 6 votes |
@org.netbeans.api.annotations.common.SuppressWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") private EditCookie getEditCookie() { try { String relativePath = client.getLocalWsdlFile(); if (relativePath != null) { JAXWSClientSupport support = JAXWSClientSupport. getJaxWsClientSupport(srcRoot); if ( support == null ){ return null; } FileObject wsdlFolder = support.getLocalWsdlFolderForClient( client.getName(),false); if (wsdlFolder != null) { FileObject wsdlFo = wsdlFolder.getFileObject(relativePath); assert wsdlFo!=null: "Cannot find local WSDL file"; //NOI18N if (wsdlFo != null) { DataObject dObj = DataObject.find(wsdlFo); return (EditCookie)dObj.getCookie(EditCookie.class); } } } } catch (java.io.IOException ex) { Logger.getLogger(JaxWsClientNode.class.getName()).log(Level.INFO, "Cannot find data object for wsdl file", ex); } return null; }
Example #12
Source File: WebFreeFormActionProvider.java From netbeans with Apache License 2.0 | 6 votes |
private void openFile(String path) { FileObject file = helper.getProjectDirectory().getFileObject(path); if (file == null) return; DataObject fileDO; try { fileDO = DataObject.find(file); } catch (DataObjectNotFoundException e) { throw new AssertionError(e); } EditCookie edit = (EditCookie)fileDO.getCookie(EditCookie.class); if (edit != null) { edit.edit(); } }
Example #13
Source File: EBGeneralAndClassPanelTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testOpenProject() throws Exception { File projectDir = new File(getDataDir(), "projects/" + Utils.EJB_PROJECT_NAME); project = (Project) J2eeProjectSupport.openProject(projectDir); assertNotNull("Project is null.", project); Thread.sleep(1000); EjbJarProject ejbJarProject = (EjbJarProject) project; ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); // deployment descriptor assertNotNull("ejb-jar.xml FileObject is null.", ddFo); ddObj = (EjbJarMultiViewDataObject) DataObject.find(ddFo); //MultiView Editor assertNotNull("MultiViewDO is null.", ddObj); EditCookie edit = (EditCookie) ddObj.getCookie(EditCookie.class); edit.edit(); Thread.sleep(1000); // select CustomerBean EnterpriseBeans beans = DDProvider.getDefault().getDDRoot(ddFo).getEnterpriseBeans(); bean = (Entity) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_NAME, "CustomerBean"); ddObj.showElement(bean); //open visual editor Utils.waitForAWTDispatchThread(); }
Example #14
Source File: EjbModuleTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testOpenProject() throws Exception { File projectDir = new File(getDataDir(), "projects/TestCMP"); project = (Project) J2eeProjectSupport.openProject(projectDir); assertNotNull("Project is null.", project); Thread.sleep(1000); EjbJarProject ejbJarProject = (EjbJarProject) project; ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); // deployment descriptor assertNotNull("ejb-jar.xml FileObject is null.", ddFo); ddObj = (EjbJarMultiViewDataObject) DataObject.find(ddFo); //MultiView Editor assertNotNull("MultiViewDO is null.", ddObj); EditCookie edit = (EditCookie) ddObj.getCookie(EditCookie.class); edit.edit(); Thread.sleep(1000); }
Example #15
Source File: XMLJ2eeDataObject.java From netbeans with Apache License 2.0 | 6 votes |
public XMLJ2eeDataObject(FileObject pf, MultiFileLoader loader) throws org.openide.loaders.DataObjectExistsException { super(pf,loader); CookieSet cs = getCookieSet(); cs.add(XMLJ2eeEditorSupport.class, this); cs.add(EditCookie.class, this); cs.add(EditorCookie.class, this); cs.add(LineCookie.class, this); cs.add(PrintCookie.class, this); cs.add(CloseCookie.class, this); // added CheckXMLCookie InputSource in = DataObjectAdapters.inputSource(this); CheckXMLCookie checkCookie = new CheckXMLSupport(in); cs.add(checkCookie); }
Example #16
Source File: JaxWsClientNode.java From netbeans with Apache License 2.0 | 6 votes |
private EditCookie getEditCookie() { try { FileObject wsdlFolder = jaxWsSupport.getWsdlFolder(false); if ( wsdlFolder == null ){ return null; } FileObject wsdlFo = wsdlFolder.getFileObject(client.getLocalWsdl()); if (wsdlFo!=null) { DataObject dObj = DataObject.find(wsdlFo); return (EditCookie)dObj.getCookie(EditCookie.class); } } catch (java.io.IOException ex) { ErrorManager.getDefault().log(ex.getLocalizedMessage()); return null; } return null; }
Example #17
Source File: CMPRelationshipsTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testOpenProject() throws Exception { File projectDir = new File(getDataDir(), "projects/TestCMPRelationships"); project = (Project) J2eeProjectSupport.openProject(projectDir); assertNotNull("Project is null.", project); Thread.sleep(1000); EjbJarProject ejbJarProject = (EjbJarProject) project; ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); // deployment descriptor assertNotNull("ejb-jar.xml FileObject is null.", ddFo); ddObj = (EjbJarMultiViewDataObject) DataObject.find(ddFo); //MultiView Editor assertNotNull("MultiViewDO is null.", ddObj); EditCookie edit = (EditCookie) ddObj.getCookie(EditCookie.class); edit.edit(); Thread.sleep(1000); }
Example #18
Source File: JspHyperlinkProvider.java From netbeans with Apache License 2.0 | 6 votes |
private void openInEditor(FileObject fObj) { if (fObj != null) { DataObject dobj; try { dobj = DataObject.find(fObj); } catch (DataObjectNotFoundException e) { Exceptions.printStackTrace(e); return; } if (dobj != null) { Node.Cookie cookie = dobj.getLookup().lookup(EditCookie.class); if (cookie != null) { ((EditCookie) cookie).edit(); } } } }
Example #19
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 #20
Source File: CatalogEntryNode.java From netbeans with Apache License 2.0 | 6 votes |
public void edit() { try { URI uri = new URI(getSystemID()); File file = new File(uri); FileObject fo = FileUtil.toFileObject(file); boolean editPossible=false; if (fo!=null) { DataObject obj = DataObject.find(fo); EditCookie editCookie = obj.getCookie(EditCookie.class); if (editCookie!=null) { editPossible=true; editCookie.edit(); } } if (!editPossible) org.openide.DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( NbBundle.getMessage(CatalogEntryNode.class, "MSG_CannotOpenURI",getSystemID()), //NOI18N NotifyDescriptor.INFORMATION_MESSAGE)); } catch (Throwable ex) { ErrorManager.getDefault().notify(ex); } }
Example #21
Source File: XmlMultiViewEditorTest.java From netbeans with Apache License 2.0 | 6 votes |
private BookDataObject initDataObject() throws IOException { BookDataObject ret = null; File f = Helper.getBookFile(getDataDir(), getWorkDir()); FileObject fo = FileUtil.toFileObject(f); assertNotNull(fo); doSetPreferredLoader(fo, loader); DataObject dObj = DataObject.find(fo); assertNotNull("Book DataObject not found", dObj); assertEquals(BookDataObject.class, dObj.getClass()); ret = (BookDataObject) dObj; ((EditCookie) ret.getCookie(EditCookie.class)).edit(); // wait to open the document Helper.waitForDispatchThread(); XmlMultiViewEditorSupport editor = (XmlMultiViewEditorSupport) ret.getCookie(EditorCookie.class); Document doc = Helper.getDocument(editor); assertTrue("The document is empty :", doc == null || doc.getLength() > 0); return ret; }
Example #22
Source File: XMLWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
private void formatXML(FileObject fobj){ try { DataObject dobj = DataObject.find(fobj); EditorCookie ec = dobj.getCookie(EditorCookie.class); if (ec == null) { return; } BaseDocument doc = (BaseDocument) ec.getDocument(); org.netbeans.modules.xml.text.api.XMLFormatUtil.reformat(doc, 0, doc.getLength()); EditCookie cookie = dobj.getCookie(EditCookie.class); if (cookie instanceof TextEditorSupport) { if (cookie != null) { ((TextEditorSupport) cookie).saveDocument(); } } } catch (Exception e) { //if exception , then the file will be informatted } }
Example #23
Source File: DTDWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
/** * This is where, the schema gets instantiated from the template. */ public Set instantiate (TemplateWizard wizard) throws IOException { FileObject dir = Templates.getTargetFolder( wizard ); DataFolder df = DataFolder.findFolder( dir ); FileObject template = Templates.getTemplate( wizard ); DataObject dTemplate = DataObject.find( template ); DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard)); if (dobj == null) return Collections.emptySet(); encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile()); if(!EncodingUtil.isValidEncoding(encoding)) encoding = "UTF-8"; //NOI18N EditCookie edit = dobj.getCookie(EditCookie.class); if (edit != null) { EditorCookie editorCookie = dobj.getCookie(EditorCookie.class); Document doc = (Document)editorCookie.openDocument(); fixEncoding(doc, encoding); SaveCookie save = dobj.getCookie(SaveCookie.class); if (save!=null) save.save(); } return Collections.singleton(dobj.getPrimaryFile()); }
Example #24
Source File: FastTypeProvider.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void open() { boolean success = false; try { final FileObject fo = getFileObject(); if (fo != null) { final DataObject d = DataObject.find(fo); final EditCookie cake = d.getCookie(EditCookie.class); if (cake != null) { cake.edit(); success = true; } } } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } if (!success) { Toolkit.getDefaultToolkit().beep(); } }
Example #25
Source File: ProjectFilesNode.java From netbeans with Apache License 2.0 | 5 votes |
public @Override void actionPerformed(ActionEvent e) { try { File sf = FileUtilities.getUserSettingsFile(true); EditCookie cook = DataObject.find(FileUtil.toFileObject(sf)).getLookup().lookup(EditCookie.class); if (cook != null) { cook.edit(); } } catch (DataObjectNotFoundException ex) { Logger.getLogger(ProjectFilesNode.class.getName()).log(Level.SEVERE, null, ex); } }
Example #26
Source File: JsfTemplateUtils.java From netbeans with Apache License 2.0 | 5 votes |
private void openSingle(String template) { FileObject tableTemplate = FileUtil.getConfigRoot().getFileObject(template); try { final DataObject dob = DataObject.find(tableTemplate); EventQueue.invokeLater(new Runnable() { @Override public void run() { dob.getLookup().lookup(EditCookie.class).edit(); } }); panel.cancel(); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } }
Example #27
Source File: EBDetailsAndCMPFieldPanelTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testOpenProject() throws Exception { File projectDir = new File(getDataDir(), "projects/TestCMP"); project = (Project) J2eeProjectSupport.openProject(projectDir); assertNotNull("Project is null.", project); Thread.sleep(1000); EjbJarProject ejbJarProject = (EjbJarProject) project; ddFo = ejbJarProject.getAPIEjbJar().getDeploymentDescriptor(); // deployment descriptor assertNotNull("ejb-jar.xml FileObject is null.", ddFo); ejbJar = DDProvider.getDefault().getDDRoot(ddFo); ddObj = (EjbJarMultiViewDataObject) DataObject.find(ddFo); //MultiView Editor assertNotNull("MultiViewDO is null.", ddObj); EditCookie edit = (EditCookie) ddObj.getCookie(EditCookie.class); edit.edit(); Thread.sleep(1000); // select CustomerBean EnterpriseBeans beans = DDProvider.getDefault().getDDRoot(ddFo).getEnterpriseBeans(); bean = (Entity) beans.findBeanByName(EnterpriseBeans.ENTITY, Ejb.EJB_NAME, "CustomerBean"); ddObj.showElement(bean); //open visual editor Utils.waitForAWTDispatchThread(); }
Example #28
Source File: TemplatesPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void settingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsButtonActionPerformed FileObject dir = FileUtil.getConfigFile(TEMPLATES_FOLDER+"/Properties"); if (dir == null) { settingsButton.setEnabled(false); return ; } for (Enumeration<? extends FileObject> en = dir.getChildren(true); en.hasMoreElements(); ) { FileObject fo = en.nextElement(); try { DataObject dobj = DataObject.find(fo); EditCookie ec = dobj.getLookup().lookup(EditCookie.class); if (ec != null) { ec.edit (); } else { OpenCookie oc = dobj.getLookup().lookup(OpenCookie.class); if (oc != null) { oc.open (); } else { continue; } } // Close the Templates dialog closeDialog(this); } catch (DataObjectNotFoundException ex) { continue; } } }
Example #29
Source File: NodeUtils.java From netbeans with Apache License 2.0 | 5 votes |
/** * open pom file for given FileObject, for items from local repository creates a read-only FO. * @param fo * @since 2.67 */ public static void openPomFile(FileObject fo) { DataObject dobj; try { dobj = DataObject.find(NodeUtils.readOnlyLocalRepositoryFile(fo)); EditCookie edit = dobj.getLookup().lookup(EditCookie.class); if (edit != null) { edit.edit(); } } catch (DataObjectNotFoundException ex) { LOG.log(Level.FINE, "Cannot find dataobject", ex); } }
Example #30
Source File: FXMLHyperlinkProvider.java From netbeans with Apache License 2.0 | 5 votes |
private EditCookie getEditorCookie(Document doc, int offset) { TokenHierarchy<?> th = TokenHierarchy.get(doc); TokenSequence ts = th.tokenSequence(Language.find(JavaFXEditorUtils.FXML_MIME_TYPE)); if (ts == null) { return null; } ts.move(offset); if (!ts.moveNext()) { return null; } Token t = ts.token(); FileObject fo = getFileObject(doc); String name = t.text().toString(); FileObject props = findFile(fo, name); if (props != null) { try { DataObject dobj = DataObject.find(props); return dobj.getLookup().lookup(EditCookie.class); } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } return null; }