001: package net.refractions.udig.style.internal;
002:
003: import java.util.Set;
004:
005: import net.refractions.udig.project.internal.Layer;
006: import net.refractions.udig.project.internal.StyleBlackboard;
007: import net.refractions.udig.style.IStyleConfigurator;
008:
009: public class StyleTransaction {
010:
011: /** master of styles **/
012: private StyleManager styleManager;
013:
014: /** The layer being styled **/
015: private Layer layer;
016:
017: /** The style blackboard being populated with style information **/
018: private StyleBlackboard styleBlackboard;
019:
020: public StyleTransaction(StyleManager styleManager, Layer layer,
021: Set<IStyleConfigurator> configurators) {
022: this .styleManager = styleManager;
023: this .layer = layer;
024: }
025:
026: /**
027: * Returns the layer being worked on by the transaction.
028: *
029: * @return Returns the layer.
030: *
031: public Layer getLayer() {
032: return layer;
033: }
034:
035: /**
036: * Sets the layer being worked on by the transaction.
037: * @param layer The layer to set.
038: *
039: public void setLayer( Layer layer ) {
040: this.layer = layer;
041: }
042: */
043: /**
044: * Sets the style blackboard used in the transaction.
045: *
046: * @param styleBlackboard The new style blackboard.
047: */
048: public void setStyleBlackboard(StyleBlackboard styleBlackboard) {
049: this .styleBlackboard = styleBlackboard;
050: }
051:
052: /**
053: * Returns the style blackboard being used by the transaction.
054: *
055: * @return The current style blackboard.
056: */
057: public StyleBlackboard getStyleBlackboard() {
058: return styleBlackboard;
059: }
060:
061: /**
062: *
063: * @return Returns the configurators.
064: *
065: public Set<IStyleConfigurator> getConfigurators() {
066: return styleManager.getCurrentConfigurators();
067: }*/
068:
069: /**
070: * @param configurators The configurators to set.
071: *
072: public void setConfigurators( Set<IStyleConfigurator> configurators ) {
073: this.configurators = configurators;
074: }*/
075:
076: /**
077: * Starts the styling transaction.
078: */
079: public void begin() {
080: // create a clone of the blackboard
081: styleBlackboard = (StyleBlackboard) styleManager
082: .getCurrentLayer().getStyleBlackboard().clone();
083:
084: // for (IStyleConfigurator config : styleManager.getStyleConfigurators()) {
085: // config.focus(styleManager.getCurrentLayer(),styleBlackboard);
086: // }
087: }
088:
089: /*
090: public void suspend() {
091: //tell all the configurators to save state to the blackboard
092: for (IStyleConfigurator config : configurators) {
093: //only apply if ui has been created
094: if (config.getControl() != null && !config.getControl().isDisposed()) {
095: config.apply();
096: }
097: }
098: }*/
099: /*
100: public void resume() {
101: //reset the blackboard for the configurators
102: for (IStyleConfigurator config : configurators) {
103: config.setLayer(styleManager.getCurrentLayer());
104: config.setStyleBlackboard(styleBlackboard);
105:
106: //only init if ui has been created
107: if (config.getControl() != null && !config.getControl().isDisposed()) {
108: config.refresh();
109: }
110: }
111: }
112: */
113: public void rollback() {
114: begin();
115: }
116:
117: public void commit() {
118: //tell all the configurators to save state to the blackboard
119: //for (IStyleConfigurator config : styleManager.getStyleConfigurators()) {
120: //only apply if ui has been created
121: //if (config.getControl() != null) { config.apply();}
122: //}
123: ApplyStyleCommand applyCommand = new ApplyStyleCommand(layer,
124: layer.getStyleBlackboard(), styleBlackboard);
125: layer.getContextModel().getMap().sendCommandASync(applyCommand);
126: }
127: }
128:
129: //class ApplyStyleCommand implements UndoableCommand {
130: //
131: // StyleBlackboard oldStyleBlackboard;
132: // StyleBlackboard newStyleBlackboard;
133: // Layer layer;
134: //
135: // public ApplyStyleCommand(
136: // Layer layer, StyleBlackboard oldStyleBlackboard, StyleBlackboard newStyleBlackboard
137: // ) {
138: // this.oldStyleBlackboard = oldStyleBlackboard;
139: // this.newStyleBlackboard = newStyleBlackboard;
140: // this.layer = layer;
141: // }
142: //
143: // /*
144: // * @see net.refractions.udig.project.command.UndoableCommand#rollback()
145: // */
146: // public void rollback() throws Exception {
147: // //overwrite with the orignal blackboard
148: // layer.setStyleBlackboard(oldStyleBlackboard);
149: // }
150: //
151: // public void run() throws Exception {
152: // //overwrite with new blackboard
153: // layer.setStyleBlackboard(newStyleBlackboard);
154: // }
155: //
156: // /*
157: // * @see net.refractions.udig.project.command.MapCommand#copy()
158: // */
159: // public MapCommand copy() {
160: // return new ApplyStyleCommand(layer,oldStyleBlackboard,newStyleBlackboard);
161: // }
162: //
163: // /**
164: // * @see net.refractions.udig.project.command.MapCommand#getName()
165: // */
166: // public String getName() {
167: // return Messages.StyleTransaction_apply_style;
168: // }
169: //
170: //}
|