KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > edit > AbstractDrawComponentContainerEditPart


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 28.10.2004 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.edit;
9
10 import java.beans.PropertyChangeEvent JavaDoc;
11 import java.util.List JavaDoc;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.draw2d.FreeformLayout;
15 import org.eclipse.draw2d.IFigure;
16 import org.eclipse.draw2d.XYLayout;
17 import org.eclipse.gef.EditPolicy;
18 import org.eclipse.gef.editpolicies.SnapFeedbackPolicy;
19
20 import com.nightlabs.editor2d.DrawComponentContainer;
21 import com.nightlabs.editor2d.editpolicy.DrawComponentContainerEditPolicy;
22 import com.nightlabs.editor2d.editpolicy.DrawComponentContainerXYLayoutPolicy;
23 import com.nightlabs.editor2d.editpolicy.DrawComponentEditPolicy;
24 import com.nightlabs.editor2d.figures.ContainerDrawComponentFigure;
25
26
27 public abstract class AbstractDrawComponentContainerEditPart
28 extends AbstractDrawComponentEditPart
29 {
30   public static final Logger LOGGER = Logger.getLogger(AbstractDrawComponentContainerEditPart.class);
31   
32   /**
33    * @param drawComponent
34    */

35   public AbstractDrawComponentContainerEditPart(DrawComponentContainer drawComponentContainer) {
36     super(drawComponentContainer);
37   }
38
39 // protected abstract IFigure createFigure();
40
protected IFigure createFigure()
41   {
42     ContainerDrawComponentFigure figure = new ContainerDrawComponentFigure();
43     figure.setLayoutManager(new FreeformLayout());
44     figure.setDrawComponent(getDrawComponent());
45     addRenderer(figure);
46     addZoomListener(figure);
47     return figure;
48   }
49   
50 // /* (non-Javadoc)
51
// * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
52
// */
53
// protected IFigure createFigure() {
54
// Figure f = new Figure();
55
// f.setLayoutManager(new FreeformLayout());
56
// return f;
57
// }
58

59   /* (non-Javadoc)
60    * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
61    */

62   protected void createEditPolicies()
63   {
64     installEditPolicy(EditPolicy.COMPONENT_ROLE, new DrawComponentEditPolicy());
65         installEditPolicy(EditPolicy.CONTAINER_ROLE, new DrawComponentContainerEditPolicy());
66         XYLayout layout = (XYLayout) getContentPane().getLayoutManager();
67         installEditPolicy(EditPolicy.LAYOUT_ROLE, new DrawComponentContainerXYLayoutPolicy(layout));
68         installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, null);
69         installEditPolicy("Snap Feedback", new SnapFeedbackPolicy()); //$NON-NLS-1$
70
}
71   
72     protected void propertyChanged(PropertyChangeEvent JavaDoc evt)
73     {
74         super.propertyChanged(evt);
75         String JavaDoc propertyName = evt.getPropertyName();
76         if (propertyName.equals(DrawComponentContainer.CHILD_ADDED)) {
77             LOGGER.debug(propertyName);
78             refreshChildren();
79         }
80         else if (propertyName.equals(DrawComponentContainer.CHILD_REMOVED)) {
81             LOGGER.debug(propertyName);
82             refreshChildren();
83         }
84     }
85
86 // public void notifyChanged(Notification notification)
87
// {
88
// int type = notification.getEventType();
89
// int featureId = notification.getFeatureID(Editor2DPackage.class);
90
//
91
// if (featureId == Editor2DPackage.DRAW_COMPONENT_CONTAINER__DRAW_COMPONENTS)
92
// {
93
// switch (type)
94
// {
95
// case Notification.ADD :
96
// LOGGER.debug("DRAW_COMPONENT_CONTAINER__DRAW_COMPONENTS ADD Notified!");
97
// refreshChildren();
98
// break;
99
// case Notification.REMOVE :
100
// LOGGER.debug("DRAW_COMPONENT_CONTAINER__DRAW_COMPONENTS REMOVE Notified!");
101
// refreshChildren();
102
// break;
103
// case Notification.ADD_MANY :
104
// LOGGER.debug("DRAW_COMPONENT_CONTAINER__DRAW_COMPONENTS ADD MANY Notified!");
105
// refreshChildren();
106
// break;
107
// case Notification.REMOVE_MANY :
108
// LOGGER.debug("DRAW_COMPONENT_CONTAINER__DRAW_COMPONENTS REMOVE MANY Notified!");
109
// refreshChildren();
110
// break;
111
// case Notification.SET :
112
// LOGGER.debug("DRAW_COMPONENT_CONTAINER__DRAW_COMPONENTS SET Notified!");
113
// refreshChildren();
114
// break;
115
// }
116
// }
117
// if (type == Notification.SET) {
118
// LOGGER.debug("DrawComponentContainer SET Notified!");
119
// refreshVisuals();
120
// }
121
//
122
// super.notifyChanged( notification );
123
// }
124

125   protected List JavaDoc getModelChildren()
126   {
127     return ((DrawComponentContainer)getModel()).getDrawComponents();
128   }
129 }
130
Popular Tags