| 1 | /* |
| 2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.usage.edit.parts; |
| 5 | |
| 6 | import org.eclipse.draw2d.FigureUtilities; |
| 7 | import org.eclipse.draw2d.Label; |
| 8 | import org.eclipse.draw2d.geometry.Dimension; |
| 9 | import org.eclipse.draw2d.geometry.Rectangle; |
| 10 | import org.eclipse.gef.EditPart; |
| 11 | import org.eclipse.gef.EditPartFactory; |
| 12 | import org.eclipse.gef.tools.CellEditorLocator; |
| 13 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; |
| 14 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
| 15 | import org.eclipse.gmf.runtime.notation.View; |
| 16 | import org.eclipse.jface.viewers.CellEditor; |
| 17 | import org.eclipse.swt.SWT; |
| 18 | import org.eclipse.swt.widgets.Text; |
| 19 | |
| 20 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
| 21 | |
| 22 | /** |
| 23 | * @generated |
| 24 | */ |
| 25 | public class PalladioComponentModelEditPartFactory implements EditPartFactory { |
| 26 | |
| 27 | /** |
| 28 | * @generated |
| 29 | */ |
| 30 | public EditPart createEditPart(EditPart context, Object model) { |
| 31 | if (model instanceof View) { |
| 32 | View view = (View) model; |
| 33 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) { |
| 34 | |
| 35 | case UsageScenarioEditPart.VISUAL_ID: |
| 36 | return new UsageScenarioEditPart(view); |
| 37 | |
| 38 | case UsageScenario2EditPart.VISUAL_ID: |
| 39 | return new UsageScenario2EditPart(view); |
| 40 | |
| 41 | case UsageScenarioLabelEditPart.VISUAL_ID: |
| 42 | return new UsageScenarioLabelEditPart(view); |
| 43 | |
| 44 | case ScenarioBehaviourEditPart.VISUAL_ID: |
| 45 | return new ScenarioBehaviourEditPart(view); |
| 46 | |
| 47 | case StartEditPart.VISUAL_ID: |
| 48 | return new StartEditPart(view); |
| 49 | |
| 50 | case StopEditPart.VISUAL_ID: |
| 51 | return new StopEditPart(view); |
| 52 | |
| 53 | case EntryLevelSystemCallEditPart.VISUAL_ID: |
| 54 | return new EntryLevelSystemCallEditPart(view); |
| 55 | |
| 56 | case ComponentExternalCallNameLabelEditPart.VISUAL_ID: |
| 57 | return new ComponentExternalCallNameLabelEditPart(view); |
| 58 | |
| 59 | case VariableUsageEditPart.VISUAL_ID: |
| 60 | return new VariableUsageEditPart(view); |
| 61 | |
| 62 | case WrappingLabelEditPart.VISUAL_ID: |
| 63 | return new WrappingLabelEditPart(view); |
| 64 | |
| 65 | case VariableCharacterisationEditPart.VISUAL_ID: |
| 66 | return new VariableCharacterisationEditPart(view); |
| 67 | |
| 68 | case LoopEditPart.VISUAL_ID: |
| 69 | return new LoopEditPart(view); |
| 70 | |
| 71 | case UsageLoopIterationsLabelEditPart.VISUAL_ID: |
| 72 | return new UsageLoopIterationsLabelEditPart(view); |
| 73 | |
| 74 | case ScenarioBehaviour2EditPart.VISUAL_ID: |
| 75 | return new ScenarioBehaviour2EditPart(view); |
| 76 | |
| 77 | case BranchEditPart.VISUAL_ID: |
| 78 | return new BranchEditPart(view); |
| 79 | |
| 80 | case BranchTransitionEditPart.VISUAL_ID: |
| 81 | return new BranchTransitionEditPart(view); |
| 82 | |
| 83 | case BranchTransitionBranchProbabilityEditPart.VISUAL_ID: |
| 84 | return new BranchTransitionBranchProbabilityEditPart(view); |
| 85 | |
| 86 | case ScenarioBehaviour3EditPart.VISUAL_ID: |
| 87 | return new ScenarioBehaviour3EditPart(view); |
| 88 | |
| 89 | case DelayEditPart.VISUAL_ID: |
| 90 | return new DelayEditPart(view); |
| 91 | |
| 92 | case DelayEntityNameEditPart.VISUAL_ID: |
| 93 | return new DelayEntityNameEditPart(view); |
| 94 | |
| 95 | case DelayLabelSpecEditPart.VISUAL_ID: |
| 96 | return new DelayLabelSpecEditPart(view); |
| 97 | |
| 98 | case ClosedWorkloadEditPart.VISUAL_ID: |
| 99 | return new ClosedWorkloadEditPart(view); |
| 100 | |
| 101 | case ClosedWorkloadPopulationEditPart.VISUAL_ID: |
| 102 | return new ClosedWorkloadPopulationEditPart(view); |
| 103 | |
| 104 | case ClosedWorkloadTitleLabelEditPart.VISUAL_ID: |
| 105 | return new ClosedWorkloadTitleLabelEditPart(view); |
| 106 | |
| 107 | case ClosedWorkloadThinkTimeLabelEditPart.VISUAL_ID: |
| 108 | return new ClosedWorkloadThinkTimeLabelEditPart(view); |
| 109 | |
| 110 | case OpenWorkloadEditPart.VISUAL_ID: |
| 111 | return new OpenWorkloadEditPart(view); |
| 112 | |
| 113 | case OpenWorkloadSpecLabelEditPart.VISUAL_ID: |
| 114 | return new OpenWorkloadSpecLabelEditPart(view); |
| 115 | |
| 116 | case UsageScenarioUsageScenarioCompartmentEditPart.VISUAL_ID: |
| 117 | return new UsageScenarioUsageScenarioCompartmentEditPart(view); |
| 118 | |
| 119 | case ScenarioBehaviourScenarioBehaviourStepsCompartmentEditPart.VISUAL_ID: |
| 120 | return new ScenarioBehaviourScenarioBehaviourStepsCompartmentEditPart( |
| 121 | view); |
| 122 | |
| 123 | case EntryLevelSystemCallParameterUsageEditPart.VISUAL_ID: |
| 124 | return new EntryLevelSystemCallParameterUsageEditPart(view); |
| 125 | |
| 126 | case VariableUsageVariableCharacterisationEditPart.VISUAL_ID: |
| 127 | return new VariableUsageVariableCharacterisationEditPart(view); |
| 128 | |
| 129 | case ScenarioBehaviourScenarioBehaviourStepsCompartment2EditPart.VISUAL_ID: |
| 130 | return new ScenarioBehaviourScenarioBehaviourStepsCompartment2EditPart( |
| 131 | view); |
| 132 | |
| 133 | case BranchUsageBranchTransitionsCompartmentEditPart.VISUAL_ID: |
| 134 | return new BranchUsageBranchTransitionsCompartmentEditPart(view); |
| 135 | |
| 136 | case ScenarioBehaviourScenarioBehaviourStepsCompartment3EditPart.VISUAL_ID: |
| 137 | return new ScenarioBehaviourScenarioBehaviourStepsCompartment3EditPart( |
| 138 | view); |
| 139 | |
| 140 | case AbstractUserActionSuccessorEditPart.VISUAL_ID: |
| 141 | return new AbstractUserActionSuccessorEditPart(view); |
| 142 | |
| 143 | } |
| 144 | } |
| 145 | return createUnrecognizedEditPart(context, model); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @generated |
| 150 | */ |
| 151 | private EditPart createUnrecognizedEditPart(EditPart context, Object model) { |
| 152 | // Handle creation of unrecognized child node EditParts here |
| 153 | return null; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @generated |
| 158 | */ |
| 159 | public static CellEditorLocator getTextCellEditorLocator( |
| 160 | ITextAwareEditPart source) { |
| 161 | if (source.getFigure() instanceof WrappingLabel) |
| 162 | return new TextCellEditorLocator((WrappingLabel) source.getFigure()); |
| 163 | else { |
| 164 | return new LabelCellEditorLocator((Label) source.getFigure()); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @generated |
| 170 | */ |
| 171 | static private class TextCellEditorLocator implements CellEditorLocator { |
| 172 | |
| 173 | /** |
| 174 | * @generated |
| 175 | */ |
| 176 | private WrappingLabel wrapLabel; |
| 177 | |
| 178 | /** |
| 179 | * @generated |
| 180 | */ |
| 181 | public TextCellEditorLocator(WrappingLabel wrapLabel) { |
| 182 | this.wrapLabel = wrapLabel; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * @generated |
| 187 | */ |
| 188 | public WrappingLabel getWrapLabel() { |
| 189 | return wrapLabel; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * @generated |
| 194 | */ |
| 195 | public void relocate(CellEditor celleditor) { |
| 196 | Text text = (Text) celleditor.getControl(); |
| 197 | Rectangle rect = getWrapLabel().getTextBounds().getCopy(); |
| 198 | getWrapLabel().translateToAbsolute(rect); |
| 199 | if (getWrapLabel().isTextWrapOn() |
| 200 | && getWrapLabel().getText().length() > 0) { |
| 201 | rect.setSize(new Dimension(text.computeSize(rect.width, |
| 202 | SWT.DEFAULT))); |
| 203 | } else { |
| 204 | int avr = FigureUtilities.getFontMetrics(text.getFont()) |
| 205 | .getAverageCharWidth(); |
| 206 | rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, |
| 207 | SWT.DEFAULT)).expand(avr * 2, 0)); |
| 208 | } |
| 209 | if (!rect.equals(new Rectangle(text.getBounds()))) { |
| 210 | text.setBounds(rect.x, rect.y, rect.width, rect.height); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * @generated |
| 218 | */ |
| 219 | private static class LabelCellEditorLocator implements CellEditorLocator { |
| 220 | |
| 221 | /** |
| 222 | * @generated |
| 223 | */ |
| 224 | private Label label; |
| 225 | |
| 226 | /** |
| 227 | * @generated |
| 228 | */ |
| 229 | public LabelCellEditorLocator(Label label) { |
| 230 | this.label = label; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @generated |
| 235 | */ |
| 236 | public Label getLabel() { |
| 237 | return label; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @generated |
| 242 | */ |
| 243 | public void relocate(CellEditor celleditor) { |
| 244 | Text text = (Text) celleditor.getControl(); |
| 245 | Rectangle rect = getLabel().getTextBounds().getCopy(); |
| 246 | getLabel().translateToAbsolute(rect); |
| 247 | int avr = FigureUtilities.getFontMetrics(text.getFont()) |
| 248 | .getAverageCharWidth(); |
| 249 | rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, |
| 250 | SWT.DEFAULT)).expand(avr * 2, 0)); |
| 251 | if (!rect.equals(new Rectangle(text.getBounds()))) { |
| 252 | text.setBounds(rect.x, rect.y, rect.width, rect.height); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |