001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.printing.ui.internal.editor.parts;
018:
019: import net.refractions.udig.printing.model.Box;
020: import net.refractions.udig.printing.model.PropertyListener;
021: import net.refractions.udig.printing.model.impl.MapBoxPrinter;
022: import net.refractions.udig.printing.ui.internal.Messages;
023: import net.refractions.udig.printing.ui.internal.editor.figures.BoxFigure;
024: import net.refractions.udig.printing.ui.internal.editor.policies.MapEditPolicy;
025:
026: import org.eclipse.draw2d.IFigure;
027: import org.eclipse.gef.EditPolicy;
028: import org.eclipse.gef.Request;
029: import org.eclipse.gef.editparts.AbstractTreeEditPart;
030: import org.eclipse.gef.tools.DirectEditManager;
031:
032: /**
033: * Provides ...TODO summary sentence
034: * <p>
035: * TODO Description
036: * </p><p>
037: * Responsibilities:
038: * <ul>
039: * <li>
040: * <li>
041: * </ul>
042: * </p><p>
043: * Example Use:<pre><code>
044: * MapTreePart x = new MapTreePart( ... );
045: * TODO code example
046: * </code></pre>
047: * </p>
048: * @author Richard Gould
049: * @since 0.3
050: */
051: public class MapTreePart extends AbstractTreeEditPart {
052: protected DirectEditManager manager;
053: private InternalPropertyListener listener = new InternalPropertyListener();
054:
055: /**
056: * Construct <code>MapTreePart</code>.
057: *
058: * @param box
059: */
060: public MapTreePart(Box box) {
061: super (box);
062: }
063:
064: @SuppressWarnings("unchecked")
065: public void activate() {
066: if (isActive()) {
067: return;
068: }
069:
070: super .activate();
071: ((Box) getModel()).eAdapters().add(listener);
072: }
073:
074: public void deactivate() {
075: if (!isActive()) {
076: return;
077: }
078: super .deactivate();
079: ((Box) getModel()).eAdapters().remove(listener);
080: }
081:
082: protected void refreshVisuals() {
083: setWidgetText(Messages.MapTreePart_mapLabel
084: + ((MapBoxPrinter) ((Box) getModel()).getBoxPrinter())
085: .getMap().getName());
086: }
087:
088: public void performRequest(Request request) {
089: super .performRequest(request);
090: }
091:
092: protected IFigure createFigure() {
093: return new BoxFigure();
094: }
095:
096: protected void createEditPolicies() {
097: super .createEditPolicies();
098: installEditPolicy(EditPolicy.COMPONENT_ROLE,
099: new MapEditPolicy());
100: }
101:
102: protected class InternalPropertyListener extends PropertyListener {
103:
104: protected void locationChanged() {
105: refreshVisuals();
106: }
107:
108: protected void sizeChanged() {
109: refreshVisuals();
110: }
111:
112: @Override
113: protected void boxesChanged() {
114: super.boxesChanged();
115: }
116: }
117: }
|