Search in sources :

Example 1 with Savable

use of org.netbeans.api.actions.Savable in project netbeans-rcp-lite by outersky.

the class DataObject method setModified.

/**
 * Set whether the object is considered modified.
 * Also fires a change event.
 * If the new value is <code>true</code>, the data object is added into a {@link #getRegistry registry} of opened data objects.
 * If the new value is <code>false</code>,
 * the data object is removed from the registry.
 */
public void setModified(boolean modif) {
    boolean log = OBJ_LOG.isLoggable(Level.FINE);
    synchronized (LOCK) {
        if (log) {
            // NOI18N
            String msg = "setModified(): modif=" + modif + ", original-modif=" + this.modif;
            if (OBJ_LOG.isLoggable(Level.FINEST)) {
                OBJ_LOG.log(Level.FINEST, msg, new Exception());
            } else {
                OBJ_LOG.log(Level.FINE, msg);
            }
        }
        if (this.modif == modif) {
            return;
        }
        this.modif = modif;
    }
    Savable present = getLookup().lookup(AbstractSavable.class);
    if (log) {
        // NOI18N
        OBJ_LOG.log(Level.FINE, "setModified(): present={0}", new Object[] { present });
    }
    if (modif) {
        syncModified.add(this);
        if (present == null) {
            new DOSavable(this).add();
        }
    } else {
        syncModified.remove(this);
        if (present == null) {
            new DOSavable(this).remove();
        }
        Unmodify un = getLookup().lookup(Unmodify.class);
        if (un != null) {
            un.unmodify();
        }
    }
    firePropertyChange(DataObject.PROP_MODIFIED, !modif ? Boolean.TRUE : Boolean.FALSE, modif ? Boolean.TRUE : Boolean.FALSE);
}
Also used : Savable(org.netbeans.api.actions.Savable) AbstractSavable(org.netbeans.spi.actions.AbstractSavable) Unmodify(org.netbeans.modules.openide.loaders.Unmodify)

Example 2 with Savable

use of org.netbeans.api.actions.Savable in project netbeans-rcp-lite by outersky.

the class ExitDialog method save.

/**
 * Save the files from the listbox
 * @param all true- all files, false - just selected
 */
private void save(boolean all) {
    Object[] array = ((all) ? listModel.toArray() : list.getSelectedValues());
    int i, count = ((array == null) ? 0 : array.length);
    // index of last removed item
    int index = 0;
    for (i = 0; i < count; i++) {
        Savable nextObject = (Savable) array[i];
        index = listModel.indexOf(nextObject);
        save(nextObject);
    }
    if (listModel.isEmpty())
        theEnd();
    else {
        // reset selection to new item at the same index if available
        if (index < 0)
            index = 0;
        else if (index > listModel.size() - 1) {
            index = listModel.size() - 1;
        }
        list.setSelectedIndex(index);
    }
}
Also used : Savable(org.netbeans.api.actions.Savable)

Example 3 with Savable

use of org.netbeans.api.actions.Savable in project netbeans-rcp-lite by outersky.

the class SaveAction method performAction.

protected void performAction(final Node[] activatedNodes) {
    for (int i = 0; i < activatedNodes.length; i++) {
        Node node = activatedNodes[i];
        Savable sc = node.getLookup().lookup(Savable.class);
        assert sc != null : "Savable must be present on " + node + ". " + "See http://www.netbeans.org/issues/show_bug.cgi?id=68285 for details on overriding " + node.getClass().getName() + ".getCookie correctly.";
        // avoid NPE if disabled assertions
        if (sc == null)
            return;
        performAction(sc, node);
    }
}
Also used : Savable(org.netbeans.api.actions.Savable) Node(org.openide.nodes.Node)

Example 4 with Savable

use of org.netbeans.api.actions.Savable in project netbeans-rcp-lite by outersky.

the class AbstractSavable method save.

/**
 * Implementation of {@link Savable#save} contract. Calls
 * {@link #handleSave} and {@link #unregister}.
 *
 * @throws IOException if call to {@link #handleSave} throws IOException
 */
@Override
public final void save() throws IOException {
    Template<AbstractSavable> t = new Template<AbstractSavable>(AbstractSavable.class, null, this);
    for (Savable s : Savable.REGISTRY.lookup(t).allInstances()) {
        if (s == this) {
            handleSave();
            unregister();
            return;
        }
    }
    LOG.log(Level.WARNING, // NOI18N
    "Savable {0} is not in Savable.REGISTRY! " + "Have not you forgotten to call register() in constructor?", // NOI18N
    getClass());
}
Also used : Savable(org.netbeans.api.actions.Savable) Template(org.openide.util.Lookup.Template)

Example 5 with Savable

use of org.netbeans.api.actions.Savable 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)

Aggregations

Savable (org.netbeans.api.actions.Savable)7 Node (org.openide.nodes.Node)4 ActionEvent (java.awt.event.ActionEvent)3 IOException (java.io.IOException)3 CloneableTopComponent (org.openide.windows.CloneableTopComponent)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)2 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2 GraphDataObject (au.gov.asd.tac.constellation.graph.file.GraphDataObject)2 GraphObjectUtilities (au.gov.asd.tac.constellation.graph.file.GraphObjectUtilities)2 SaveNotification (au.gov.asd.tac.constellation.graph.file.SaveNotification)2 GraphJsonWriter (au.gov.asd.tac.constellation.graph.file.io.GraphJsonWriter)2 NebulaDataObject (au.gov.asd.tac.constellation.graph.file.nebula.NebulaDataObject)2 AutosaveUtilities (au.gov.asd.tac.constellation.graph.file.save.AutosaveUtilities)2 GraphVisualManagerFactory (au.gov.asd.tac.constellation.graph.interaction.framework.GraphVisualManagerFactory)2 CopyToClipboardAction (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToClipboardAction)2 CutToClipboardAction (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CutToClipboardAction)2 PasteFromClipboardAction (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.PasteFromClipboardAction)2 ContractAllCompositesAction (au.gov.asd.tac.constellation.graph.interaction.plugins.composite.ContractAllCompositesAction)2