Java Code Examples for org.openide.cookies.EditCookie#edit()

The following examples show how to use org.openide.cookies.EditCookie#edit() . 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: FastTypeProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ModelUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: EBGeneralAndClassPanelTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 4
Source File: CatalogEntryNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 5
Source File: CMPRelationshipsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 6
Source File: WebFreeFormActionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 7
Source File: NoMVCLookupTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 8
Source File: XMLDataObjectTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testLookup() throws Exception {
    MockLookup.setInstances(XMLDataLoader.getLoader(XMLDataLoader.class));

    FileObject document = FileUtil.toFileObject(
            FileUtil.normalizeFile(getDataDir())).getFileObject("dummyXMLDocument.xml");

    assertNotNull(document);

    DataObject object = DataObject.find(document);
    assertTrue(object instanceof XMLDataObject);

    XMLDataObject dataObject = (XMLDataObject) object;
    assertNotNull(dataObject.getLookup().lookup(FileObject.class));

    EditCookie ec = (EditCookie)dataObject.getCookie(EditCookie.class);
    assertNotNull("Editor cookie found", ec);

    EditCookie lkp = dataObject.getLookup().lookup(EditCookie.class);
    assertEquals("Cookies are the same", ec, lkp);

    OpenCookie lkp2 = dataObject.getLookup().lookup(OpenCookie.class);

    lkp.edit();
    lkp2.open();

    Set<?> all = null;
    for (int i = 0; i < 10; i++) {
        Thread.sleep(1000);
        all = WindowManager.getDefault().getRegistry().getOpened();
        if (all.size() > 0) {
            break;
        }
    }

    assertEquals("There is just one TC: " + all, 1, all.size());

    assertEquals("Cookies are the same", lkp, lkp2);
}
 
Example 9
Source File: EBDetailsAndCMPFieldPanelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 10
Source File: EditAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void performAction(final Node[] activatedNodes) {
    for (int i = 0; i < activatedNodes.length; i++) {
        EditCookie es = activatedNodes[i].getCookie(EditCookie.class);

        if (es != null) {
            es.edit();
        }
    }
}
 
Example 11
Source File: NbApplicationAdapter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void openFiles(List<File> files) {
    for (File f : files) {
        if (f.exists() && !f.isDirectory()) {
            FileObject obj = FileUtil.toFileObject(f);
            if (obj != null) {
                try {
                    DataObject dob = DataObject.find(obj);
                    OpenCookie oc = dob.getLookup().lookup (OpenCookie.class);
                    if (oc != null) {
                        oc.open();
                    } else {
                        EditCookie ec = dob.getLookup().lookup(EditCookie.class);
                        if (ec != null) {
                            ec.edit();
                        } else {
                            ViewCookie v = dob.getLookup().lookup(ViewCookie.class);
                            if (v != null) {
                                v.view();
                            }
                        }
                    }
                } catch (DataObjectNotFoundException ex) {
                    Logger.getLogger(NbApplicationAdapter.class.getName()).log(Level.INFO, f.getAbsolutePath(), ex);
                }
            }
        }
    }
}
 
Example 12
Source File: TemplatesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 13
Source File: WildflyEditConfigAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(final Node[] activatedNodes) {
    for (int i = 0; i < activatedNodes.length; i++) {
        EditCookie es = (EditCookie) activatedNodes[i].getLookup().lookup(EditCookie.class);
        if (es != null) {
            es.edit();
        }
    }
}
 
Example 14
Source File: POMInheritancePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void actionPerformed(ActionEvent e) {
    if (dobj != null) {
        EditCookie ec = dobj.getLookup().lookup(EditCookie.class);
        if (ec != null) {
            ec.edit();
        }
    }
}
 
Example 15
Source File: ProjectFilesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 16
Source File: NodeUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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 17
Source File: JaxWsClientNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void open() {
    EditCookie ec = getEditCookie();
    if (ec != null) {
        ec.edit();
    }
}
 
Example 18
Source File: ResourceBundleBrandingPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void open() {
    EditCookie originalEC = getOriginal().getCookie(EditCookie.class);
    if (null != originalEC)
        originalEC.edit();
}
 
Example 19
Source File: InternationalizationResourceBundleBrandingPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void open() {
    EditCookie originalEC = getOriginal().getCookie(EditCookie.class);
    if (null != originalEC)
        originalEC.edit();
}
 
Example 20
Source File: InternationalizationResourceBundleBrandingPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void open() {
    EditCookie originalEC = getOriginal().getCookie(EditCookie.class);
    if (null != originalEC)
        originalEC.edit();
}