1 8 package com.nightlabs.editor2d.edit; 9 10 import java.beans.PropertyChangeEvent ; 11 import java.util.List ; 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 35 public AbstractDrawComponentContainerEditPart(DrawComponentContainer drawComponentContainer) { 36 super(drawComponentContainer); 37 } 38 39 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 59 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()); } 71 72 protected void propertyChanged(PropertyChangeEvent evt) 73 { 74 super.propertyChanged(evt); 75 String 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 125 protected List getModelChildren() 126 { 127 return ((DrawComponentContainer)getModel()).getDrawComponents(); 128 } 129 } 130 | Popular Tags |