/* * License (BSD Style License): * Copyright (c) 2011 * Software Engineering * Department of Computer Science * Technische Universität Darmstadt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Software Engineering Group or Technische * Universität Darmstadt nor the names of its contributors may be used to * endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ package de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts; import org.eclipse.draw2d.FigureUtilities; import org.eclipse.draw2d.Label; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPartFactory; import org.eclipse.gef.tools.CellEditorLocator; import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Text; /** * @generated */ public class VespucciEditPartFactory implements EditPartFactory { /** * @generated */ public EditPart createEditPart(EditPart context, Object model) { if (model instanceof View) { View view = (View) model; switch (de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciVisualIDRegistry.getVisualID(view)) { case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ShapesDiagramEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ShapesDiagramEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleDescriptionEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleDescriptionEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.DummyEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.DummyEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.DummyNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.DummyNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.Ensemble2EditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.Ensemble2EditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleName2EditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleName2EditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleDescription2EditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleDescription2EditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.Dummy2EditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.Dummy2EditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.DummyName2EditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.DummyName2EditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleCompartmentEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleCompartmentEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleDescriptionCompartmentEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleDescriptionCompartmentEditPart( view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleCompartment2EditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleCompartment2EditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleDescriptionCompartment2EditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.EnsembleEnsembleDescriptionCompartment2EditPart( view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.IncomingEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.IncomingEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.IncomingNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.IncomingNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.OutgoingEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.OutgoingEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.OutgoingNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.OutgoingNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.InAndOutEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.InAndOutEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.InAndOutNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.InAndOutNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.NotAllowedEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.NotAllowedEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.NotAllowedNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.NotAllowedNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ExpectedEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ExpectedEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ExpectedNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ExpectedNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalIncomingEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalIncomingEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalIncomingNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalIncomingNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalOutgoingEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalOutgoingEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalOutgoingNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.GlobalOutgoingNameEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ViolationEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ViolationEditPart(view); case de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ViolationNameEditPart.VISUAL_ID: return new de.tud.cs.st.vespucci.vespucci_model.diagram.edit.parts.ViolationNameEditPart(view); } } return createUnrecognizedEditPart(context, model); } /** * @generated */ private EditPart createUnrecognizedEditPart(EditPart context, Object model) { // Handle creation of unrecognized child node EditParts here return null; } /** * @generated */ public static CellEditorLocator getTextCellEditorLocator(ITextAwareEditPart source) { if (source.getFigure() instanceof WrappingLabel) return new TextCellEditorLocator((WrappingLabel) source.getFigure()); else { return new LabelCellEditorLocator((Label) source.getFigure()); } } /** * @generated */ static private class TextCellEditorLocator implements CellEditorLocator { /** * @generated */ private WrappingLabel wrapLabel; /** * @generated */ public TextCellEditorLocator(WrappingLabel wrapLabel) { this.wrapLabel = wrapLabel; } /** * @generated */ public WrappingLabel getWrapLabel() { return wrapLabel; } /** * @generated */ public void relocate(CellEditor celleditor) { Text text = (Text) celleditor.getControl(); Rectangle rect = getWrapLabel().getTextBounds().getCopy(); getWrapLabel().translateToAbsolute(rect); if (!text.getFont().isDisposed()) { if (getWrapLabel().isTextWrapOn() && getWrapLabel().getText().length() > 0) { rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT))); } else { int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth(); rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0)); } } if (!rect.equals(new Rectangle(text.getBounds()))) { text.setBounds(rect.x, rect.y, rect.width, rect.height); } } } /** * @generated */ private static class LabelCellEditorLocator implements CellEditorLocator { /** * @generated */ private Label label; /** * @generated */ public LabelCellEditorLocator(Label label) { this.label = label; } /** * @generated */ public Label getLabel() { return label; } /** * @generated */ public void relocate(CellEditor celleditor) { Text text = (Text) celleditor.getControl(); Rectangle rect = getLabel().getTextBounds().getCopy(); getLabel().translateToAbsolute(rect); if (!text.getFont().isDisposed()) { int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth(); rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0)); } if (!rect.equals(new Rectangle(text.getBounds()))) { text.setBounds(rect.x, rect.y, rect.width, rect.height); } } } }