Search in sources :

Example 1 with CloneableTopComponent

use of org.openide.windows.CloneableTopComponent in project netbeans-rcp-lite by outersky.

the class MultiViewPeer method updateName.

// from CloneableEditor.Pane
public void updateName() {
    // is called before setMultiViewDescriptions() need to check for null.
    if (model != null) {
        for (MultiViewDescription mvd : model.getDescriptions()) {
            if (mvd instanceof ContextAwareDescription && ((ContextAwareDescription) mvd).isSplitDescription())
                // #240371 - don't update name from spit elements
                continue;
            MultiViewElement el = model.getElementForDescription(mvd, MultiViewCloneableTopComponent.isSourceView(mvd));
            if (el == null) {
                continue;
            }
            if (el.getVisualRepresentation() instanceof Pane) {
                Pane pane = (Pane) el.getVisualRepresentation();
                pane.updateName();
                final CloneableTopComponent tc = pane.getComponent();
                peer.setDisplayName(tc.getDisplayName());
                peer.setIcon(tc.getIcon());
                if (!Arrays.asList(tc.getPropertyChangeListeners()).contains(propListener)) {
                    tc.addPropertyChangeListener(propListener);
                }
            }
        }
    }
}
Also used : MultiViewElement(org.netbeans.core.spi.multiview.MultiViewElement) CloneableTopComponent(org.openide.windows.CloneableTopComponent) MultiViewDescription(org.netbeans.core.spi.multiview.MultiViewDescription) Pane(org.openide.text.CloneableEditorSupport.Pane) JSplitPane(javax.swing.JSplitPane) JEditorPane(javax.swing.JEditorPane)

Example 2 with CloneableTopComponent

use of org.openide.windows.CloneableTopComponent in project netbeans-rcp-lite by outersky.

the class MultiViewPeer method addPropertyChangeListeners.

private void addPropertyChangeListeners() {
    if (null != model) {
        for (MultiViewDescription mvd : model.getDescriptions()) {
            if (mvd instanceof ContextAwareDescription && ((ContextAwareDescription) mvd).isSplitDescription())
                // #240371 - don't update name from spit elements
                continue;
            MultiViewElement el = model.getElementForDescription(mvd, false);
            if (el == null) {
                continue;
            }
            if (el.getVisualRepresentation() instanceof Pane) {
                Pane pane = (Pane) el.getVisualRepresentation();
                final CloneableTopComponent tc = pane.getComponent();
                if (!Arrays.asList(tc.getPropertyChangeListeners()).contains(propListener)) {
                    tc.addPropertyChangeListener(propListener);
                }
            }
        }
    }
}
Also used : MultiViewElement(org.netbeans.core.spi.multiview.MultiViewElement) CloneableTopComponent(org.openide.windows.CloneableTopComponent) MultiViewDescription(org.netbeans.core.spi.multiview.MultiViewDescription) Pane(org.openide.text.CloneableEditorSupport.Pane) JSplitPane(javax.swing.JSplitPane) JEditorPane(javax.swing.JEditorPane)

Example 3 with CloneableTopComponent

use of org.openide.windows.CloneableTopComponent in project netbeans-rcp-lite by outersky.

the class MultiViewCloneableEditor method canCloseElement.

@Messages({ "# {0} - file name", "MSG_SaveModified=File {0} is modified. Save?", "MSG_SaveModified_no_name=File is modified. Save?" })
@Override
public CloseOperationState canCloseElement() {
    final CloneableEditorSupport sup = getLookup().lookup(CloneableEditorSupport.class);
    Enumeration<CloneableTopComponent> en = getReference().getComponents();
    if (en.hasMoreElements()) {
        en.nextElement();
        if (en.hasMoreElements()) {
            // at least two is OK
            return CloseOperationState.STATE_OK;
        }
    }
    Savable sav = getLookup().lookup(Savable.class);
    if (sav != null) {
        AbstractAction save = new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    sup.saveDocument();
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        };
        try {
            if (sav.getClass().getMethod("toString").getDeclaringClass() != Object.class) {
                save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(sav));
            } else {
                Logger.getLogger(MultiViewCloneableEditor.class.getName()).log(Level.WARNING, "Need to override toString() to contain the file name in o.n.api.action.Savable {0} with lookup {1}", new Object[] { sav.getClass(), getLookup().lookupAll(Object.class) });
                Node n = getLookup().lookup(Node.class);
                if (n != null) {
                    // #201696: compatibility fallback.
                    save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(n.getDisplayName()));
                } else {
                    save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified_no_name());
                }
            }
        } catch (NoSuchMethodException x) {
            assert false : x;
        }
        return MultiViewFactory.createUnsafeCloseState("editor", save, null);
    }
    return CloseOperationState.STATE_OK;
}
Also used : CloneableTopComponent(org.openide.windows.CloneableTopComponent) Savable(org.netbeans.api.actions.Savable) ActionEvent(java.awt.event.ActionEvent) Node(org.openide.nodes.Node) IOException(java.io.IOException) CloneableEditorSupport(org.openide.text.CloneableEditorSupport) Messages(org.openide.util.NbBundle.Messages)

Example 4 with CloneableTopComponent

use of org.openide.windows.CloneableTopComponent in project constellation by constellation-app.

the class RecentFiles method removeFile.

/**
 * Removes file represented by given TopComponent from the list
 */
private static void removeFile(final TopComponent tc) {
    historyProbablyValid = false;
    if (tc instanceof CloneableTopComponent) {
        final String path = obtainPath(tc);
        if (path != null) {
            synchronized (HISTORY_LOCK) {
                final HistoryItem hItem = findHistoryItem(path);
                if (hItem != null) {
                    HISTORY.remove(hItem);
                }
                store();
            }
        }
    }
}
Also used : CloneableTopComponent(org.openide.windows.CloneableTopComponent) HistoryItem(au.gov.asd.tac.constellation.graph.file.open.RecentFiles.HistoryItem)

Aggregations

CloneableTopComponent (org.openide.windows.CloneableTopComponent)4 JEditorPane (javax.swing.JEditorPane)2 JSplitPane (javax.swing.JSplitPane)2 MultiViewDescription (org.netbeans.core.spi.multiview.MultiViewDescription)2 MultiViewElement (org.netbeans.core.spi.multiview.MultiViewElement)2 Pane (org.openide.text.CloneableEditorSupport.Pane)2 HistoryItem (au.gov.asd.tac.constellation.graph.file.open.RecentFiles.HistoryItem)1 ActionEvent (java.awt.event.ActionEvent)1 IOException (java.io.IOException)1 Savable (org.netbeans.api.actions.Savable)1 Node (org.openide.nodes.Node)1 CloneableEditorSupport (org.openide.text.CloneableEditorSupport)1 Messages (org.openide.util.NbBundle.Messages)1