| 1 | /* |
| 2 | * Copyright 2009, SDQ, IPD, Uni Karlsruhe (TH) |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.resource.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.resource.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 ResourceEnvironmentEditPart.VISUAL_ID: |
| 36 | return new ResourceEnvironmentEditPart(view); |
| 37 | |
| 38 | case ResourceContainerEditPart.VISUAL_ID: |
| 39 | return new ResourceContainerEditPart(view); |
| 40 | |
| 41 | case ResourceContainerEntityNameEditPart.VISUAL_ID: |
| 42 | return new ResourceContainerEntityNameEditPart(view); |
| 43 | |
| 44 | case LinkingResource2EditPart.VISUAL_ID: |
| 45 | return new LinkingResource2EditPart(view); |
| 46 | |
| 47 | case LinkingResourceEntityNameEditPart.VISUAL_ID: |
| 48 | return new LinkingResourceEntityNameEditPart(view); |
| 49 | |
| 50 | case ProcessingResourceSpecificationEditPart.VISUAL_ID: |
| 51 | return new ProcessingResourceSpecificationEditPart(view); |
| 52 | |
| 53 | case ProcessingResourceSpecificationMTTFEditPart.VISUAL_ID: |
| 54 | return new ProcessingResourceSpecificationMTTFEditPart(view); |
| 55 | |
| 56 | case ProcessingResourceSpecificationMTTREditPart.VISUAL_ID: |
| 57 | return new ProcessingResourceSpecificationMTTREditPart(view); |
| 58 | |
| 59 | case ProcessingResourceSpecificationSchedulingPolicyEditPart.VISUAL_ID: |
| 60 | return new ProcessingResourceSpecificationSchedulingPolicyEditPart( |
| 61 | view); |
| 62 | |
| 63 | case ProcessingResourceSpecificationNumberOfReplicasEditPart.VISUAL_ID: |
| 64 | return new ProcessingResourceSpecificationNumberOfReplicasEditPart( |
| 65 | view); |
| 66 | |
| 67 | case WrappingLabelEditPart.VISUAL_ID: |
| 68 | return new WrappingLabelEditPart(view); |
| 69 | |
| 70 | case ProcessingResourceSpecificationActiveResourceTypeLabelEditPart.VISUAL_ID: |
| 71 | return new ProcessingResourceSpecificationActiveResourceTypeLabelEditPart( |
| 72 | view); |
| 73 | |
| 74 | case CommunicationLinkResourceSpecificationEditPart.VISUAL_ID: |
| 75 | return new CommunicationLinkResourceSpecificationEditPart(view); |
| 76 | |
| 77 | case CommunicationLinkResourceSpecificationFailureProbabilityEditPart.VISUAL_ID: |
| 78 | return new CommunicationLinkResourceSpecificationFailureProbabilityEditPart( |
| 79 | view); |
| 80 | |
| 81 | case CommunicationLinkResourceSpecificationLatencyLabelEditPart.VISUAL_ID: |
| 82 | return new CommunicationLinkResourceSpecificationLatencyLabelEditPart( |
| 83 | view); |
| 84 | |
| 85 | case CommunicationLinkResourceSpecificationThroughputLabelEditPart.VISUAL_ID: |
| 86 | return new CommunicationLinkResourceSpecificationThroughputLabelEditPart( |
| 87 | view); |
| 88 | |
| 89 | case WrappingLabel2EditPart.VISUAL_ID: |
| 90 | return new WrappingLabel2EditPart(view); |
| 91 | |
| 92 | case ResourceContainerResourceContainerCompartmentEditPart.VISUAL_ID: |
| 93 | return new ResourceContainerResourceContainerCompartmentEditPart( |
| 94 | view); |
| 95 | |
| 96 | case ProcessingResourceSpecificationProcessingResourceSpecificationCompartmentEditPart.VISUAL_ID: |
| 97 | return new ProcessingResourceSpecificationProcessingResourceSpecificationCompartmentEditPart( |
| 98 | view); |
| 99 | |
| 100 | case LinkingResourceNetworkSwitchCompartmentEditPart.VISUAL_ID: |
| 101 | return new LinkingResourceNetworkSwitchCompartmentEditPart(view); |
| 102 | |
| 103 | case LinkingResourceConnectedResourceContainers_LinkingResourceEditPart.VISUAL_ID: |
| 104 | return new LinkingResourceConnectedResourceContainers_LinkingResourceEditPart( |
| 105 | view); |
| 106 | |
| 107 | } |
| 108 | } |
| 109 | return createUnrecognizedEditPart(context, model); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @generated |
| 114 | */ |
| 115 | private EditPart createUnrecognizedEditPart(EditPart context, Object model) { |
| 116 | // Handle creation of unrecognized child node EditParts here |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @generated |
| 122 | */ |
| 123 | public static CellEditorLocator getTextCellEditorLocator( |
| 124 | ITextAwareEditPart source) { |
| 125 | if (source.getFigure() instanceof WrappingLabel) |
| 126 | return new TextCellEditorLocator((WrappingLabel) source.getFigure()); |
| 127 | else { |
| 128 | return new LabelCellEditorLocator((Label) source.getFigure()); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @generated |
| 134 | */ |
| 135 | static private class TextCellEditorLocator implements CellEditorLocator { |
| 136 | |
| 137 | /** |
| 138 | * @generated |
| 139 | */ |
| 140 | private WrappingLabel wrapLabel; |
| 141 | |
| 142 | /** |
| 143 | * @generated |
| 144 | */ |
| 145 | public TextCellEditorLocator(WrappingLabel wrapLabel) { |
| 146 | this.wrapLabel = wrapLabel; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * @generated |
| 151 | */ |
| 152 | public WrappingLabel getWrapLabel() { |
| 153 | return wrapLabel; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @generated |
| 158 | */ |
| 159 | public void relocate(CellEditor celleditor) { |
| 160 | Text text = (Text) celleditor.getControl(); |
| 161 | Rectangle rect = getWrapLabel().getTextBounds().getCopy(); |
| 162 | getWrapLabel().translateToAbsolute(rect); |
| 163 | if (getWrapLabel().isTextWrapOn() |
| 164 | && getWrapLabel().getText().length() > 0) { |
| 165 | rect.setSize(new Dimension(text.computeSize(rect.width, |
| 166 | SWT.DEFAULT))); |
| 167 | } else { |
| 168 | int avr = FigureUtilities.getFontMetrics(text.getFont()) |
| 169 | .getAverageCharWidth(); |
| 170 | rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, |
| 171 | SWT.DEFAULT)).expand(avr * 2, 0)); |
| 172 | } |
| 173 | if (!rect.equals(new Rectangle(text.getBounds()))) { |
| 174 | text.setBounds(rect.x, rect.y, rect.width, rect.height); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @generated |
| 181 | */ |
| 182 | private static class LabelCellEditorLocator implements CellEditorLocator { |
| 183 | |
| 184 | /** |
| 185 | * @generated |
| 186 | */ |
| 187 | private Label label; |
| 188 | |
| 189 | /** |
| 190 | * @generated |
| 191 | */ |
| 192 | public LabelCellEditorLocator(Label label) { |
| 193 | this.label = label; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * @generated |
| 198 | */ |
| 199 | public Label getLabel() { |
| 200 | return label; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * @generated |
| 205 | */ |
| 206 | public void relocate(CellEditor celleditor) { |
| 207 | Text text = (Text) celleditor.getControl(); |
| 208 | Rectangle rect = getLabel().getTextBounds().getCopy(); |
| 209 | getLabel().translateToAbsolute(rect); |
| 210 | int avr = FigureUtilities.getFontMetrics(text.getFont()) |
| 211 | .getAverageCharWidth(); |
| 212 | rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, |
| 213 | SWT.DEFAULT)).expand(avr * 2, 0)); |
| 214 | if (!rect.equals(new Rectangle(text.getBounds()))) { |
| 215 | text.setBounds(rect.x, rect.y, rect.width, rect.height); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |