Java Code Examples for org.openide.cookies.EditorCookie

The following examples show how to use org.openide.cookies.EditorCookie. These examples are extracted from open source projects. 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 Project: netbeans   Source File: RelationshipMappingRename.java    License: Apache License 2.0 6 votes vote down vote up
@Override
 public PositionBounds getPosition() {
    try {
        DataObject dobj = DataObject.find(getParentFile());
        if (dobj != null) {
            EditorCookie.Observable obs = (EditorCookie.Observable)dobj.getLookup().lookup(EditorCookie.Observable.class);
            if (obs != null && obs instanceof CloneableEditorSupport) {
                CloneableEditorSupport supp = (CloneableEditorSupport)obs;

            PositionBounds bounds = new PositionBounds(
                    supp.createPositionRef(loc[0], Position.Bias.Forward),
                    supp.createPositionRef(Math.max(loc[0], loc[1]), Position.Bias.Forward)
                    );

            return bounds;
        }
        }
    } catch (DataObjectNotFoundException ex) {
        LOG.log(Level.INFO, "Can't resolve", ex);//NOI18N
    }
    return null;
}
 
Example 2
Source Project: netbeans   Source File: RelationshipMappingWhereUsed.java    License: Apache License 2.0 6 votes vote down vote up
@Override
 public PositionBounds getPosition() {
    try {
        DataObject dobj = DataObject.find(getParentFile());
        if (dobj != null) {
            EditorCookie.Observable obs = (EditorCookie.Observable)dobj.getLookup().lookup(EditorCookie.Observable.class);
            if (obs != null && obs instanceof CloneableEditorSupport) {
                CloneableEditorSupport supp = (CloneableEditorSupport)obs;

            PositionBounds bounds = new PositionBounds(
                    supp.createPositionRef(loc[0], Position.Bias.Forward),
                    supp.createPositionRef(Math.max(loc[0], loc[1]), Position.Bias.Forward)
                    );

            return bounds;
        }
        }
    } catch (DataObjectNotFoundException ex) {
        LOG.log(Level.INFO, "Can't resolve", ex);//NOI18N
    }
    return null;
}
 
Example 3
Source Project: netbeans   Source File: SourceFileObject.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected final Long isDirty() {
    final FileObject file = getHandle().resolveFileObject(false);
    if (file == null) {
        return null;
    }
    final DataObject.Registry regs = DataObject.getRegistry();
    final Set<DataObject> modified = regs.getModifiedSet();
    for (DataObject dobj : modified) {
        if (file.equals(dobj.getPrimaryFile())) {
            final EditorCookie ec = dobj.getCookie(EditorCookie.class);
            if (ec != null) {
                final Document doc = ec.getDocument();
                if (doc != null) {
                    return DocumentUtilities.getDocumentTimestamp(doc);
                }
            }
        }
    }
    return null;
}
 
Example 4
Source Project: netbeans   Source File: UtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
private void doTestDefaultIndent(String code, String insertCode, String expectedResult) throws Exception {
    clearWorkDir();
    FileObject wd = FileUtil.toFileObject(getWorkDir());
    FileObject sourceFile1 = wd.createData("Test1.txt");
    EditorCookie ec = sourceFile1.getLookup().lookup(EditorCookie.class);
    Document doc = ec.openDocument();
    int insertPos = code.indexOf("|");
    code = code.replace("|", "");
    doc.insertString(0, code, null);
    javax.swing.text.Position caret = doc.createPosition(insertPos);
    doc.insertString(insertPos, insertCode, null);
    List<TextEdit> edits = Utils.computeDefaultOnTypeIndent(doc, insertPos, Utils.createPosition(doc, insertPos), insertCode);
    Utils.applyEditsNoLock(doc, edits);
    int expectedPos = expectedResult.indexOf("|");
    expectedResult = expectedResult.replace("|", "");
    assertEquals(expectedResult, doc.getText(0, doc.getLength()));
    assertEquals(expectedPos, caret.getOffset());
    LifecycleManager.getDefault().saveAll();
}
 
Example 5
Source Project: netbeans   Source File: GoldenFileTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    File dataDir = getDataDir();
    fname = getName().replace("test", "");
    File f = new File(dataDir, getClass().getName().
            replaceAll("\\.", "/") + "/" + fname + ".fxml");
    
    File w = new File(getWorkDir(), f.getName());
    InputStream is = new FileInputStream(f);
    OutputStream os = new FileOutputStream(w);
    FileUtil.copy(is, os);
    os.close();
    is.close();
    FileObject fo = FileUtil.toFileObject(w);
    sourceDO = DataObject.find(fo);
    document = ((EditorCookie)sourceDO.getCookie(EditorCookie.class)).openDocument();
    hierarchy = TokenHierarchy.get(document);
}
 
Example 6
Source Project: netbeans   Source File: HintsPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
    final HintMetadata selectedHint = getSelectedHint();
    final String selectedHintId = selectedHint.id;
    DataObject dob = getDataObject(selectedHint);
    EditorCookie ec = dob.getCookie(EditorCookie.class);
    try {
        ec.saveDocument();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    RulesManager.getInstance().reload();
    cpBased.reset();
    errorTreeModel = constructTM(Utilities.getBatchSupportedHints(cpBased).keySet(), false);
    setModel(errorTreeModel);
    if (logic != null) {
        logic.errorTreeModel = errorTreeModel;
    }
    select(getHintByName(selectedHintId));
    customHintCodeBeforeEditing = null;
    cancelEditActionPerformed(evt);
    hasNewHints = true;
}
 
Example 7
Source Project: netbeans   Source File: JShellEnvironment.java    License: Apache License 2.0 6 votes vote down vote up
private void postCloseCleanup() {
    try {
        // try to close the dataobject
        DataObject d = DataObject.find(getConsoleFile());
        EditorCookie cake = d.getLookup().lookup(EditorCookie.class);
        cake.close();
        // discard the dataobject
        synchronized (this) {
            if (document == null) {
                return;
            }
            document = null;
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    if (controlsIO) {
        inputOutput.closeInputOutput();
    }
    ShellRegistry.get().closed(this);
}
 
Example 8
Source Project: netbeans   Source File: ResourceStringLoader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    FileObject closedFile = null;
    
    if (!EditorCookie.Observable.PROP_DOCUMENT.equals(evt.getPropertyName())) {
        return;
    }
    synchronized (this) {
        Document old = (Document)evt.getOldValue();
        if (old != null && docWL != null) {
            old.removeDocumentListener(docWL);
            docWL = null;
        }
        Document nue = (Document)evt.getNewValue();
        if (nue != null) {
            nue.addDocumentListener(docWL = WeakListeners.document(this, nue));
        } else {
            closedFile = extractFileObject(old);
        }
    }
    if (closedFile != null) {
        invalidate(closedFile);
    }
}
 
Example 9
Source Project: netbeans   Source File: VcsAnnotateAction.java    License: Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    if (visible()) {
        JEditorPane pane = activatedEditorPane();
        AnnotationBarManager.hideAnnotationBar(pane);
    } else {
        EditorCookie ec = activatedEditorCookie();
        if (ec == null) return;
        
        JEditorPane[] panes = ec.getOpenedPanes();
        if (panes == null) {
            ec.open();
        }
        panes = ec.getOpenedPanes();
        if (panes == null) {
            return;
        }
        final JEditorPane currentPane = panes[0];
        
        AnnotationBar ab = AnnotationBarManager.showAnnotationBar(currentPane);
        ab.setAnnotationMessage(NbBundle.getMessage(VcsAnnotateAction.class, "CTL_AnnotationSubstitute")); // NOI18N;
        
        computeAnnotationsAsync(ab);
    }
}
 
Example 10
Source Project: netbeans   Source File: ResourceHyperlinkProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean openFile(FileObject file) {
    if (file == null) {
        return false;
    }
    DataObject dObj;
    try {
        dObj = DataObject.find(file);
    } catch (DataObjectNotFoundException ex) {
        return false;
    }
    EditorCookie editorCookie = dObj.getCookie(EditorCookie.class);
    if (editorCookie == null) {
        return false;
    }
    editorCookie.open();
    return true;
}
 
Example 11
Source Project: netbeans   Source File: MultiDiffPanelController.java    License: Apache License 2.0 6 votes vote down vote up
public MultiDiffPanelController (File file, Revision rev1, Revision rev2, int requestedRightLine) {
    this(null, rev1, rev2, true);
    diffViewPanel = new PlaceholderPanel();
    diffViewPanel.setComponent(getInfoPanelLoading());
    this.requestedRightLine = requestedRightLine;
    this.popupAllowed = false;
    replaceVerticalSplitPane(diffViewPanel);
    initToolbarButtons();
    initNextPrevActions();
    for (JComponent c : new JComponent[] { panel.tgbHeadVsIndex, panel.tgbHeadVsWorking, panel.tgbIndexVsWorking }) {
        c.setVisible(false);
    }
    // mimics refreshSetups()
    Setup s = new Setup(file, rev1, rev2, null);
    GitLocalFileNode fNode = new GitLocalFileNode(Git.getInstance().getRepositoryRoot(file), file);
    EditorCookie cookie = DiffUtils.getEditorCookie(s);
    s.setNode(new DiffLocalNode(fNode, s, cookie, Mode.HEAD_VS_WORKING_TREE));
    Map<File, Setup> localSetups = Collections.singletonMap(file, s);
    setSetups(localSetups, getCookiesFromSetups(localSetups));
    setDiffIndex(s, 0, false);
    dpt = new DiffPrepareTask(setups.values().toArray(new Setup[setups.size()]));
    prepareTask = RP.create(dpt);
    prepareTask.schedule(0);
}
 
Example 12
Source Project: netbeans   Source File: ConfigFileSpringBeanSourceTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testPropertyParseWithoutPNamespace() throws Exception {
    String contents = TestUtils.createXMLConfigText(
            "<bean id='foo' name='bar baz' " +
            "parent='father' factory-bean='factory' factory-method='createMe' " +
            "class='org.example.Foo' p:p2='v2' p:p3-ref='v3'>" +
            "<property name='p1' value='v1'/>" + 
            "</bean>", false);
    TestUtils.copyStringToFile(contents, configFile);
    DataObject dataObject = DataObject.find(FileUtil.toFileObject(configFile));
    BaseDocument doc = (BaseDocument)dataObject.getCookie(EditorCookie.class).openDocument();
    ConfigFileSpringBeanSource source = new ConfigFileSpringBeanSource();
    source.parse(doc);
    List<SpringBean> beans = source.getBeans();
    assertEquals(1, beans.size());
    SpringBean bean = beans.get(0);
    assertSame(bean, source.findBean("foo"));
    Set<SpringBeanProperty> properties = bean.getProperties();
    assertEquals(1, properties.size());
}
 
Example 13
Source Project: netbeans   Source File: GsfDataObject.java    License: Apache License 2.0 6 votes vote down vote up
public GsfDataObject(FileObject pf, MultiFileLoader loader, Language language) throws DataObjectExistsException {
    super(pf, loader);

    // If the user creates a file with a filename where we can't figure out the language
    // (e.g. the PHP New File wizard doesn't enforce a file extension, so if you create
    // a file named "pie.class" (issue 124044) the data loader doesn't know which language
    // to associate this with since it isn't a GSF file extension or mimetype). However
    // during template creation we know the language anyway so we can use it. On subsequent
    // IDE restarts the file won't be recognized so the user will have to rename or
    // add a new file extension to file type mapping.
    if (language == null) {
        language = templateLanguage;
    }
    this.language = language;
    getCookieSet().add(new Class[]{
            GenericEditorSupport.class, // NOI18N
            SaveAsCapable.class, Openable.class, EditorCookie.Observable.class, 
            PrintCookie.class, CloseCookie.class, Editable.class, LineCookie.class,
            DataEditorSupport.class, CloneableEditorSupport.class,
            CloneableOpenSupport.class
        }, new EditorSupportFactory());
}
 
Example 14
Source Project: netbeans   Source File: AbstractRefactoringElement.java    License: Apache License 2.0 6 votes vote down vote up
public PositionBounds getPosition() {
    try {
        DataObject dobj = DataObject.find(getParentFile());
        if (dobj != null) {
            EditorCookie.Observable obs = (EditorCookie.Observable)dobj.getCookie(EditorCookie.Observable.class);
            if (obs != null && obs instanceof CloneableEditorSupport) {
                CloneableEditorSupport supp = (CloneableEditorSupport)obs;

                if (loc == null) {
                    loc = location();
                }
            PositionBounds bounds = new PositionBounds(
                    supp.createPositionRef(loc[0], Position.Bias.Forward),
                    supp.createPositionRef(Math.max(loc[0], loc[1]), Position.Bias.Forward)
                    );
            
            return bounds;
        }
        }
    } catch (DataObjectNotFoundException ex) {
        ex.printStackTrace();
    }
    return null;
}
 
Example 15
Source Project: netbeans   Source File: NavigatorContent.java    License: Apache License 2.0 6 votes vote down vote up
private JTextComponent findActivePane() {
    DataObject d = peerDO;
    LOG.fine(this + ": findActivePane DataObject=" + d);
    if (d == null) {
        return null;
    }
    EditorCookie ec = (EditorCookie)d.getCookie(EditorCookie.class);
    if (ec == null) {
        return null;
    }
    JTextComponent focused = EditorRegistry.focusedComponent();
    LOG.fine(this + ": findActivePane focused=" + focused);
    if (focused == null) {
        return null;
    }
    JTextComponent[] comps = ec.getOpenedPanes();
    if (comps == null) {
        return null;
    }
    for (JTextComponent c : comps) {
        if (c == focused) {
            return c;
        }
    }
    return null;
}
 
Example 16
Source Project: netbeans   Source File: DiffResultsViewForLine.java    License: Apache License 2.0 6 votes vote down vote up
private Document getSourceDocument(StreamSource ss) {
    Document sdoc = null;
    FileObject fo = ss.getLookup().lookup(FileObject.class);
    if (fo != null) {
        try {
            DataObject dao = DataObject.find(fo);
            if (dao.getPrimaryFile() == fo) {
                EditorCookie ec = dao.getCookie(EditorCookie.class);
                if (ec != null) {
                    sdoc = ec.openDocument();
                }
            }
        } catch (Exception e) {
            // fallback to other means of obtaining the source
        }
    } else {
        sdoc = ss.getLookup().lookup(Document.class);
    }
    return sdoc;
}
 
Example 17
Source Project: netbeans   Source File: OpenSupport.java    License: Apache License 2.0 6 votes vote down vote up
/** 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 18
Source Project: netbeans   Source File: HintTestTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNonJavaChangesOpenedInEditor214197() throws Exception {
    HintTest ht = HintTest.create()
                          .input("package test;\n" +
                                 "public class Test { }\n")
                          .input("test/test.txt", "1\n#foobar\n\n2", false);
    FileObject resource = ht.getSourceRoot().getFileObject("test/test.txt");
    DataObject od = DataObject.find(resource);
    EditorCookie ec = od.getLookup().lookup(EditorCookie.class);
    Document doc = ec.openDocument();
    doc.remove(0, doc.getLength());
    doc.insertString(0, "5\n6\n", null);
    ht.run(NonJavaChanges.class)
      .findWarning("1:13-1:17:verifier:Test")
      .applyFix(false)
      .assertVerbatimOutput("test/test.txt", "6\n7\n");
    Assert.assertEquals("1\n#foobar\n\n2", resource.asText("UTF-8"));
    Assert.assertEquals("6\n7\n", doc.getText(0, doc.getLength()));
}
 
Example 19
Source Project: netbeans   Source File: TplIndenterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected BaseDocument getDocument(FileObject fo, String mimeType, Language language) {
    // for some reason GsfTestBase is not using DataObjects for BaseDocument construction
    // which means that for example Java formatter which does call EditorCookie to retrieve
    // document will get difference instance of BaseDocument for indentation
    try {
        DataObject dobj = DataObject.find(fo);
        assertNotNull(dobj);

        EditorCookie ec = dobj.getLookup().lookup(EditorCookie.class);
        assertNotNull(ec);

        return (BaseDocument) ec.openDocument();
    } catch (Exception ex) {
        fail(ex.toString());
        return null;
    }
}
 
Example 20
Source Project: netbeans   Source File: ContextJspServletGenTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected BaseDocument getDocument(FileObject fo, String mimeType, Language language) {
    try {
        DataObject dobj = DataObject.find(fo);
        assertNotNull(dobj);

        EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class);
        assertNotNull(ec);

        return (BaseDocument) ec.openDocument();
    }
    catch (Exception ex) {
        fail(ex.toString());
        return null;
    }
}
 
Example 21
Source Project: netbeans   Source File: PHPFormatterTemplateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected BaseDocument getDocument(FileObject fo, String mimeType, Language language) {
    // for some reason GsfTestBase is not using DataObjects for BaseDocument construction
    // which means that for example other formatter which does call EditorCookie to retrieve
    // document will get difference instance of BaseDocument for indentation
    try {
        DataObject dobj = DataObject.find(fo);
        assertNotNull(dobj);

        EditorCookie ec = (EditorCookie) dobj.getLookup().lookup(EditorCookie.class);
        assertNotNull(ec);

        return (BaseDocument) ec.openDocument();
    } catch (Exception ex) {
        fail(ex.toString());
        return null;
    }
}
 
Example 22
Source Project: netbeans   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/** 
 * Returns current editor component instance.
 *
 * @return current editor component instance
 */
private static EditorCookie getCurrentEditorCookie () {
    Node[] nodes = TopComponent.getRegistry ().getActivatedNodes ();
    if ((nodes == null) || (nodes.length != 1)) return null;
    Node node = nodes [0];
    DataObject dob = node.getLookup().lookup (DataObject.class);
    if (dob != null && !dob.isValid()) {
        return null;
    }
    return node.getLookup().lookup (EditorCookie.class);
}
 
Example 23
Source Project: netbeans   Source File: AnnotateAction.java    License: Apache License 2.0 5 votes vote down vote up
private EditorCookie activatedEditorCookie(Node[] nodes) {
    if (nodes == null) {
        nodes = WindowManager.getDefault().getRegistry().getActivatedNodes();
    }
    if (nodes.length == 1) {
        Node node = nodes[0];
        return (EditorCookie) node.getCookie(EditorCookie.class);
    }
    return null;
}
 
Example 24
Source Project: netbeans   Source File: XmlMultiViewEditorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * Used for running test from inside the IDE by internal execution.
     *
     * @param args the command line arguments
     */
//    public static void main(String[] args) {
//        TestRunner.run(new NbTestSuite(XmlMultiViewEditorTest.class));
//    }
    

    public void testSetModifiedNestedChange() throws Exception {
        File f = Helper.getBookFile(getDataDir(), getWorkDir());
        FileObject fo = FileUtil.toFileObject(f);
        assertNotNull(fo);

        doSetPreferredLoader(fo, loader);
        final DataObject dob = DataObject.find(fo);

        assertTrue("The right object", dob instanceof XmlMultiViewDataObject);
        dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0,
                "modified", null);
        assertTrue("Should be modified.", dob.isModified());
        dob.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                String s = evt.getPropertyName();
                if (DataObject.PROP_MODIFIED.equals(s) && !dob.isModified()) {
                    dob.setModified(true);
                }
            }
        });
        dob.setModified(false);
        assertTrue("Should be still modified.", dob.isModified());
        assertNotNull("Still should have save cookie.",
                dob.getLookup().lookup(SaveCookie.class));
    }
 
Example 25
Source Project: netbeans   Source File: LineBreakpointPanel.java    License: Apache License 2.0 5 votes vote down vote up
private static int findNumLines(FileObject file) {
    DataObject dataObject;
    try {
        dataObject = DataObject.find (file);
    } catch (DataObjectNotFoundException ex) {
        return 0;
    }
    EditorCookie ec = (EditorCookie) dataObject.getCookie(EditorCookie.class);
    if (ec == null) return 0;
    ec.prepareDocument().waitFinished();
    Document d = ec.getDocument();
    if (!(d instanceof StyledDocument)) return 0;
    StyledDocument sd = (StyledDocument) d;
    return NbDocument.findLineNumber(sd, sd.getLength());
}
 
Example 26
Source Project: netbeans   Source File: GoToTypeAction.java    License: Apache License 2.0 5 votes vote down vote up
public Iterable<? extends TypeDescriptor> getSelectedTypes(final boolean visible, String initSearchText) {
    Iterable<? extends TypeDescriptor> result = Collections.emptyList();
    try {
        panel = new GoToPanel(this, multiSelection);
        dialog = createDialog(panel);

        if (initSearchText != null) {
            panel.setInitialText(initSearchText);
        } else {
            Node[] arr = TopComponent.getRegistry ().getActivatedNodes();
            if (arr.length > 0) {
                EditorCookie ec = arr[0].getCookie (EditorCookie.class);
                if (ec != null) {
                    JEditorPane recentPane = NbDocument.findRecentEditorPane(ec);
                    if (recentPane != null) {
                        initSearchText = org.netbeans.editor.Utilities.getSelectionOrIdentifier(recentPane);
                        if (initSearchText != null && org.openide.util.Utilities.isJavaIdentifier(initSearchText)) {
                            panel.setInitialText(initSearchText);
                        } else {
                            panel.setInitialText(arr[0].getName());
                        }
                    }
                }
            }
        }

        dialog.setVisible(visible);
        result = panel.getSelectedTypes();

    } catch (IOException ex) {
        ErrorManager.getDefault().notify(ex);
    }
    return result;
}
 
Example 27
Source Project: netbeans   Source File: ModificationResultTest.java    License: Apache License 2.0 5 votes vote down vote up
private void prepareTest(String code) throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject root = fs.getRoot();
    testFile = FileUtil.createData(root, "test/test.java");
    
    TestUtilities.copyStringToFile(testFile, code);
    
    DataObject od = DataObject.find(testFile);
    
    ces = (CloneableEditorSupport) od.getCookie(EditorCookie.class);
}
 
Example 28
Source Project: netbeans   Source File: MultiDiffPanelController.java    License: Apache License 2.0 5 votes vote down vote up
private Map<File, SaveCookie> getSaveCookies(EditorCookie[] editorCookies) {
    Map<File, SaveCookie> proResult = new HashMap<>();
    Set<EditorCookie> editorCookieSet = new HashSet<>(Arrays.asList(editorCookies));
    for (Map.Entry<File, EditorCookie> e : this.editorCookies.entrySet()) {
        if (editorCookieSet.contains(e.getValue())) {
            File baseFile = e.getKey();
            FileObject fileObj = FileUtil.toFileObject(baseFile);
            if (fileObj == null) {
                continue;
            }
            proResult.put(baseFile, new EditorSaveCookie(e.getValue(), fileObj.getNameExt()));
        }
    }
    return proResult;
}
 
Example 29
Source Project: netbeans   Source File: DiffFileTable.java    License: Apache License 2.0 5 votes vote down vote up
void updateNodes (Map<File, EditorCookie> editorCookies, List<DiffNode> toRemove, List<DiffNode> toRefresh, List<DiffNode> toAdd) {
    setEditorCookies(editorCookies);
    super.updateNodes(toRemove, toRefresh, toAdd);
    if (getTable().getRowCount() == 1) {
        getTable().getSelectionModel().addSelectionInterval(0, 0);
    }
}
 
Example 30
Source Project: netbeans   Source File: MultiDiffPanelController.java    License: Apache License 2.0 5 votes vote down vote up
private static Map<File, EditorCookie> getCookiesFromSetups(Map<File, Setup> localSetups) {
    Setup[] retSetups = localSetups.values().toArray(new Setup[localSetups.values().size()]);
    EditorCookie[] cookies = DiffUtils.setupsToEditorCookies(retSetups);
    Map<File, EditorCookie> map = new HashMap<File, EditorCookie>();
    for (int i = 0; i < cookies.length; ++i) {
        if (cookies[i] != null) {
            map.put(retSetups[i].getBaseFile(), cookies[i]);
        }
    }
    return map;
}