|
org.openide.awt 7.55.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.netbeans.spi.actions.AbstractSavable
public abstract class AbstractSavable
Default implementation of Savable interface and
additional contracts, including dealing with Savable.REGISTRY.
The human presentable name of the object to be saved is provided by
implementing findDisplayName(). In case this object wants
to be visually represented with an icon, it can also implement Icon
interface (and delegate to ImageUtilities.loadImageIcon(java.lang.String, boolean)
result). Here is example of typical implementation:
class MySavable extends AbstractSavable {
private final Object obj;
public MySavable(Object obj) {
this.obj = obj;
register();
}
protected String findDisplayName() {
return "My name is " + obj.toString(); // get display name somehow
}
protected void handleSave() throws IOException {
// save 'obj' somehow
}
public boolean equals(Object other) {
if (other instanceof MySavable) {
return ((MySavable)other).obj.equals(obj);
}
return false;
}
public int hashCode() {
return obj.hashCode();
}
}
| Field Summary |
|---|
| Fields inherited from interface org.netbeans.api.actions.Savable |
|---|
REGISTRY |
| Constructor Summary | |
|---|---|
protected |
AbstractSavable()
Constructor for subclasses. |
| Method Summary | |
|---|---|
abstract boolean |
equals(Object obj)
Equals and hashCode() need to be properly implemented
by subclasses to correctly implement equality contract. |
protected abstract String |
findDisplayName()
Finds suitable display name for the object this Savable
represents. |
protected abstract void |
handleSave()
To be overriden by subclasses to handle the actual save of the object. |
abstract int |
hashCode()
HashCode and equals(java.lang.Object) need to be properly implemented
by subclasses, so two Savables representing the same object
beneath are really equal and have the same hashCode(). |
protected void |
register()
Tells the system to register this Savable into Savable.REGISTRY. |
void |
save()
Implementation of Savable.save() contract. |
String |
toString()
Human descriptive, localized name of the savable. |
protected void |
unregister()
Removes this Savable from the Savable.REGISTRY (if it
is present there, by relying on equals(java.lang.Object)
and hashCode()). |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected AbstractSavable()
| Method Detail |
|---|
public final void save()
throws IOException
Savable.save() contract. Calls
handleSave() and unregister().
save in interface SavableIOException - if call to handleSave() throws IOExceptionprotected abstract String findDisplayName()
Savable
represents.
protected abstract void handleSave()
throws IOException
IOExceptionpublic abstract boolean equals(Object obj)
hashCode() need to be properly implemented
by subclasses to correctly implement equality contract.
Two Savables should be equal
if they represent the same underlying object beneath them. Without
correct implementation proper behavior of register() and
unregister() cannot be guaranteed.
equals in class Objectobj - object to compare this one to,
public abstract int hashCode()
equals(java.lang.Object) need to be properly implemented
by subclasses, so two Savables representing the same object
beneath are really equal and have the same hashCode().
hashCode in class Objectequals(java.lang.Object)protected final void register()
Savable into Savable.REGISTRY.
Only one Savable (according to equals(java.lang.Object) and
hashCode()) can be in the registry. New call to register()
replaces any previously registered and equal Savables. After this call
the Savable.REGISTRY holds a strong reference to this
which prevents this object to be garbage collected until it
is unregistered or replaced by
equal one.
protected final void unregister()
Savable from the Savable.REGISTRY (if it
is present there, by relying on equals(java.lang.Object)
and hashCode()).
public final String toString()
Savable
toString in interface SavabletoString in class Object
|
org.openide.awt 7.55.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||