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);
}
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);
}
}
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);
}
}
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());
}
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;
}
Aggregations