diff options
Diffstat (limited to 'jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature')
55 files changed, 0 insertions, 5759 deletions
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java deleted file mode 100644 index ec3cb7e3b1..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAllEntitiesFeature.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.graphiti.datatypes.IDimension; -import org.eclipse.graphiti.features.IAddFeature; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IAddContext; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.AddContext; -import org.eclipse.graphiti.features.context.impl.CustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.MappingKeys; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; - - -public class AddAllEntitiesFeature extends AbstractCustomFeature implements IAddFeature { - - int[] lowerEdges = new int[200]; - int numInARow; - private final static int DIST_FROM_EDGE_H = 50; - private final static int DIST_FROM_EDGE_V = 50; - private final static int DIST_H = 100; - private final static int DIST_V = 100; - - public AddAllEntitiesFeature(IFeatureProvider fp) { - super(fp); - } - - @Override - public boolean isAvailable(IContext ctx) { - return true; - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - @SuppressWarnings("restriction") - public void execute(ICustomContext context) { - Diagram d = getDiagram(); - JpaProject project = getTargetJPAProject(); - PersistenceUnit unit = project.getRootContextNode().getPersistenceXml(). - getPersistence().getPersistenceUnits().iterator().next(); - - - Point lowestRightestPointOfExistingDiagram = getLowestRightestPoint(d); - - for (int i = 0; i < 200; i++) { - lowerEdges[i] = lowestRightestPointOfExistingDiagram.y + - (((i % 2 == 0) ? 1 : 2) * - ((lowestRightestPointOfExistingDiagram.y == 0) ? - DIST_FROM_EDGE_V : - DIST_V)); - } - IDimension dim = getFeatureProvider().getDiagramTypeProvider().getDiagramEditor().getCurrentSize(); - int dWidth = dim.getWidth(); - numInARow = (dWidth - DIST_FROM_EDGE_H - 20 + JPAEditorConstants.ENTITY_WIDTH)/(JPAEditorConstants.ENTITY_WIDTH + DIST_H); - numInARow = (numInARow > 0) ? numInARow : 1; - - lowerEdges[0] = lowestRightestPointOfExistingDiagram.y + ((lowestRightestPointOfExistingDiagram.y == 0) ? DIST_FROM_EDGE_V : DIST_V); - - for (ClassRef classRef : unit.getClassRefs()) { - if (classRef.getJavaPersistentType() != null) { // null if - JavaPersistentType jpt = classRef.getJavaPersistentType(); - if (jpt.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - PictogramElement pe = getFeatureProvider().getPictogramElementForBusinessObject(jpt); - if (pe != null) - continue; - - final AddContext ctx = new AddContext(); - ctx.setTargetContainer(d); - ctx.setNewObject(jpt); - - IndexAndLowerEdge ie = getMinLowerEdge(); - - int x = DIST_FROM_EDGE_H + ie.index * (JPAEditorConstants.ENTITY_WIDTH + DIST_H); - ctx.setLocation(x, ie.lowerEdge); - final AddJPAEntityFeature ft = new AddJPAEntityFeature(getFeatureProvider()); - - final Diagram targetDiagram = (Diagram) ctx.getTargetContainer(); - TransactionalEditingDomain ted = ModelIntegrationUtil.getTransactionalEditingDomain(targetDiagram); - ted.getCommandStack().execute(new RecordingCommand(ted) { - @Override - protected void doExecute() { - ft.add(ctx); - } - }); - ContainerShape entityShape = (ContainerShape)getFeatureProvider().getPictogramElementForBusinessObject(jpt); - lowerEdges[ie.index] = entityShape.getGraphicsAlgorithm().getY() + entityShape.getGraphicsAlgorithm().getHeight() + DIST_V; - } - } - } - } - - private IndexAndLowerEdge getMinLowerEdge() { - IndexAndLowerEdge res = new IndexAndLowerEdge(); - res.lowerEdge = 10000000; - for (int i = 0; i < numInARow; i++) { - if (lowerEdges[i] < res.lowerEdge) { - res.lowerEdge = lowerEdges[i]; - res.index = i; - } - } - return res; - } - - private JpaProject getTargetJPAProject() { - return ModelIntegrationUtil.getProjectByDiagram(getDiagram().getName()); - } - - public static Point getLowestRightestPoint(Diagram d) { - List<Shape> shapes = d.getChildren(); - Iterator<Shape> it = shapes.iterator(); - int x = 0; - int y = 0; - while (it.hasNext()) { - Shape sh = it.next(); - int rightEdge = sh.getGraphicsAlgorithm().getX() + - sh.getGraphicsAlgorithm().getWidth(); - x = Math.max(x, rightEdge); - int lowerEdge = sh.getGraphicsAlgorithm().getY() + - sh.getGraphicsAlgorithm().getHeight(); - y = Math.max(y, lowerEdge); - } - x = Math.max(x, 3 * (DIST_H + JPAEditorConstants.ENTITY_WIDTH)); - return new Point(x, y); - } - - public PictogramElement add(IAddContext context) { - this.execute(new CustomContext()); - return null; - } - - public boolean canAdd(IAddContext context) { - return true; - } - - private class IndexAndLowerEdge { - int index; - int lowerEdge; - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAttributeFeature.java deleted file mode 100644 index 32dd9e9fb0..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddAttributeFeature.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Kiril Mitov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IAddFeature; -import org.eclipse.graphiti.features.IDirectEditingInfo; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IAddContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.AddContext; -import org.eclipse.graphiti.features.context.impl.CustomContext; -import org.eclipse.graphiti.features.custom.ICustomFeature; -import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp; - - -public class AddAttributeFeature extends AbstractAddShapeFeature { - - private IAddFeature graphicalAdd; - - private ICustomFeature expandCompartmentFeature; - - public AddAttributeFeature(IFeatureProvider fp) { - this(fp, new GraphicalAddAttributeFeature(fp), new ExpandCompartmentShapeFeature(fp)); - } - - public AddAttributeFeature(IFeatureProvider fp, IAddFeature graphicalAdd, ICustomFeature expandFeature) { - super(fp); - this.graphicalAdd = graphicalAdd; - expandCompartmentFeature = expandFeature; - } - - public PictogramElement add(final IAddContext context) { - Object o = context.getNewObject(); - if (!(o instanceof JavaPersistentAttribute)) { - return null; - } - final JavaPersistentAttribute newAttr = (JavaPersistentAttribute) o; -// JpaArtifactFactory.instance().refreshEntityModel(getFeatureProvider(), (JavaPersistentType)newAttr.getParent()); - - getFeatureProvider().putKeyToBusinessObject(getFeatureProvider().getKeyForBusinessObject(newAttr), newAttr); - PictogramElement pe = getFeatureProvider().getPictogramElementForBusinessObject(newAttr); - if (pe != null) - return pe; - - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(context.getTargetContainer()); - final Wrp wrp = new Wrp(); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - ContainerShape textShape = graphicalAdd(context.getTargetContainer(), newAttr); - expand(newAttr); - enableDirectAfterAdding(textShape); - wrp.setObj(textShape); - } - }); - return (PictogramElement)wrp.getObj(); - } - - private void expand(JavaPersistentAttribute jpa) { - ContainerShape attributeShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject(jpa); - - ICustomContext customContext = new CustomContext(new PictogramElement[] { attributeShape.getContainer() }); - expandCompartmentFeature.execute(customContext); - } - - private ContainerShape graphicalAdd(ContainerShape entityShape, JavaPersistentAttribute newAttr) { - AddContext context = new AddContext(); - context.setNewObject(newAttr); - context.setTargetContainer(entityShape); - ContainerShape textShape = (ContainerShape) graphicalAdd.add(context); - return textShape; - } - - private void enableDirectAfterAdding(ContainerShape textShape) { - GraphicsAlgorithm ga = textShape.getGraphicsAlgorithm(); - final GraphicsAlgorithm graphicsAlgorithm = ga.getGraphicsAlgorithmChildren().get(0); - if (graphicsAlgorithm instanceof Text) { - Text text = (Text) graphicsAlgorithm; - IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo(); - directEditingInfo.setMainPictogramElement(textShape); - directEditingInfo.setPictogramElement(textShape); - directEditingInfo.setGraphicsAlgorithm(text); - } - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - public boolean canAdd(IAddContext context) { - Object o = context.getNewObject(); - return o instanceof JavaPersistentAttribute; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java deleted file mode 100644 index 2da00febd6..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddJPAEntityFeature.java +++ /dev/null @@ -1,447 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IAddContext; -import org.eclipse.graphiti.features.context.ICreateContext; -import org.eclipse.graphiti.features.context.impl.CreateContext; -import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; -import org.eclipse.graphiti.mm.algorithms.Image; -import org.eclipse.graphiti.mm.algorithms.Polyline; -import org.eclipse.graphiti.mm.algorithms.Rectangle; -import org.eclipse.graphiti.mm.algorithms.RoundedRectangle; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.algorithms.styles.LineStyle; -import org.eclipse.graphiti.mm.algorithms.styles.Orientation; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.graphiti.util.IPredefinedRenderingStyle; -import org.eclipse.graphiti.util.PredefinedColoredAreas; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IPackageDeclaration; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.core.SourceType; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.context.AttributeMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaMappedSuperclass; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IAddEntityContext; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType; - - -@SuppressWarnings({ "restriction" }) -public class AddJPAEntityFeature extends AbstractAddShapeFeature { - - private IPeUtilFacade facade; - private static ContainerShape primaryShape; - private static ContainerShape relationShape; - private static ContainerShape basicShape; - - - public AddJPAEntityFeature(IFeatureProvider fp) { - super(fp); - facade = new PeUtilFacade(); - } - - public AddJPAEntityFeature(IFeatureProvider fp, IPeUtilFacade facade) { - super(fp); - this.facade = facade; - } - - public boolean canAdd(IAddContext context) { - Object newObj = context.getNewObject(); - - if (newObj instanceof JavaPersistentType) { - if (context.getTargetContainer() instanceof Diagram) { - JavaPersistentType jpt = (JavaPersistentType) newObj; - return checkJPTForAdding(jpt); - } - } else if (newObj instanceof ICompilationUnit) { - if (context.getTargetContainer() instanceof Diagram) { - ICompilationUnit cu = (ICompilationUnit) newObj; - JavaPersistentType jpt = JPAEditorUtil.getJPType(cu); - return checkJPTForAdding(jpt); - } - } if (newObj instanceof SourceType) { - if (context.getTargetContainer() instanceof Diagram) { - ICompilationUnit cu = ((SourceType)newObj).getCompilationUnit(); - JavaPersistentType jpt = JPAEditorUtil.getJPType(cu); - return checkJPTForAdding(jpt); - } - } - return false; - } - - private boolean checkJPTForAdding(JavaPersistentType jpt) { - if (jpt == null) - return false; - - PictogramElement[] pictograms = getFeatureProvider() - .getAllPictogramElementsForBusinessObject(jpt); - JpaProject proj = ModelIntegrationUtil.getProjectByDiagram(getDiagram().getName()); - if (proj != null) - if (proj != jpt.getJpaProject()) - return false; - return (pictograms == null) || (pictograms.length == 0); - } - - @Override - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - public PictogramElement add(IAddContext context) { - IJPAEditorFeatureProvider fp = getFeatureProvider(); - Object newObj = context.getNewObject(); - JavaPersistentType jpt = null; - if (newObj instanceof JavaPersistentType) { - jpt = (JavaPersistentType) newObj; - if (jpt.getMapping() instanceof JavaMappedSuperclass) { - jpt = createEntityFromExistingMappedSuperclass(fp, jpt); - } - } else if (newObj instanceof ICompilationUnit) { - ICompilationUnit cu = (ICompilationUnit) newObj; - jpt = JPAEditorUtil.getJPType(cu); - if (jpt.getMapping() instanceof JavaMappedSuperclass) { - jpt = createEntityFromExistingMappedSuperclass(fp, jpt); - } - - } else if (newObj instanceof SourceType) { - ICompilationUnit cu = ((SourceType)newObj).getCompilationUnit(); - jpt = JPAEditorUtil.getJPType(cu); - } - final Diagram targetDiagram = (Diagram) context.getTargetContainer(); - - ContainerShape entityShape = facade.createContainerShape(targetDiagram, true); - - createEntityRectangle(context, entityShape, - this.getFeatureProvider().getDiagramTypeProvider().getDiagram()); - link(entityShape, jpt); - Shape shape = Graphiti.getPeService().createShape(entityShape, false); - Polyline headerBottomLine = Graphiti.getGaService().createPolyline(shape, new int[] { 0, - 30, JPAEditorConstants.ENTITY_WIDTH, 30 }); - headerBottomLine - .setForeground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR)); - headerBottomLine.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH); - - addHeader(jpt, entityShape, JPAEditorConstants.ENTITY_WIDTH); - - createCompartments(context, jpt, entityShape); - fillCompartments(jpt,entityShape); - - String key = fp.getKeyForBusinessObject(jpt); - if (fp.getBusinessObjectForKey(key) == null) - fp.putKeyToBusinessObject(key, jpt); - - Graphiti.getPeService().createChopboxAnchor(entityShape); - entityShape.setVisible(true); - layoutPictogramElement(entityShape); - - UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp); - updateFeature.reconnect(jpt); - - return entityShape; - } - - private JavaPersistentType createEntityFromExistingMappedSuperclass( - IJPAEditorFeatureProvider fp, JavaPersistentType jpt) { - ICreateContext cont = new CreateContext(); - String packageName = null; - try { - packageName = getMappedSuperclassPackageDeclaration(fp, jpt, - packageName); - } catch (JavaModelException e) { - JPADiagramEditorPlugin.logError(e); - } - - boolean hasPrimaryKey = hasMappedSuperclassPrimaryKeyAttribute(jpt); - - CreateJPAEntityFeature createFeature = new CreateJPAEntityFeature(fp, - true, jpt.getName(), packageName, hasPrimaryKey); - Object[] objects = createFeature.create(cont); - if (objects.length != 0) { - Object obj = objects[0]; - if (obj instanceof JavaPersistentType) { - jpt = (JavaPersistentType) obj; - } - } - return jpt; - } - - private boolean hasMappedSuperclassPrimaryKeyAttribute( - JavaPersistentType jpt) { - - for (AttributeMapping map : ((JavaMappedSuperclass) jpt.getMapping()).getAllAttributeMappings()) { - if (map.getPrimaryKeyColumnName() != null) { - return true; - } - } - return false; - } - - private String getMappedSuperclassPackageDeclaration( - IJPAEditorFeatureProvider fp, JavaPersistentType jpt, - String packageName) throws JavaModelException { - IPackageDeclaration[] packages = fp.getCompilationUnit(jpt) - .getPackageDeclarations(); - if (packages.length > 0) { - IPackageDeclaration packageDecl = packages[0]; - packageName = packageDecl.getElementName(); - } - return packageName; - } - - private void createCompartments(IAddContext context, JavaPersistentType jpt, - ContainerShape entityShape) { - primaryShape = createCompartmentRectangle(entityShape, JPAEditorConstants.ENTITY_MIN_HEIGHT, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape); - relationShape = createCompartmentRectangle(entityShape, GraphicsUpdater.getNextCompartmentY(primaryShape) + JPAEditorConstants.SEPARATOR_HEIGHT, - JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes); - basicShape = createCompartmentRectangle(entityShape, GraphicsUpdater.getNextCompartmentY(relationShape) + JPAEditorConstants.SEPARATOR_HEIGHT, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes); - if (IAddEntityContext.class.isInstance(context)) { - IAddEntityContext entityContext = (IAddEntityContext) context; - GraphicsUpdater.setCollapsed(primaryShape, entityContext.isPrimaryCollapsed()); - GraphicsUpdater.setCollapsed(basicShape, entityContext.isBasicCollapsed()); - GraphicsUpdater.setCollapsed(relationShape, entityContext.isRelationCollapsed()); - } else { - GraphicsUpdater.setCollapsed(primaryShape, false); - GraphicsUpdater.setCollapsed(basicShape, false); - GraphicsUpdater.setCollapsed(relationShape, false); - } - } - - private void fillCompartments(JavaPersistentType jpt, ContainerShape entityShape) { - String[] primaryKeyAnnotations = new String[] {JPAEditorConstants.ANNOTATION_ID, JPAEditorConstants.ANNOTATION_EMBEDDED_ID}; - for(String annotation : primaryKeyAnnotations){ - addCompartmentChildren(primaryShape, jpt, annotation); - } - String[] relationAnnotations = new String[] {JPAEditorConstants.ANNOTATION_MANY_TO_MANY, - JPAEditorConstants.ANNOTATION_MANY_TO_ONE, JPAEditorConstants.ANNOTATION_ONE_TO_MANY, - JPAEditorConstants.ANNOTATION_ONE_TO_ONE}; - for(String annotation : relationAnnotations){ - addCompartmentChildren(relationShape, jpt, annotation); - } - addBasicAttributes(basicShape, jpt); - GraphicsUpdater.updateEntityShape(entityShape); - } - - private ContainerShape createCompartmentRectangle( - ContainerShape entityShape, int y, String attribTxt) { - int width = entityShape.getGraphicsAlgorithm().getWidth(); - ContainerShape containerShape = Graphiti.getPeService().createContainerShape( - entityShape, false); - Graphiti.getPeService().setPropertyValue(containerShape, - JPAEditorConstants.PROP_SHAPE_TYPE, ShapeType.COMPARTMENT - .toString()); - Rectangle rect = addCompartmentRectangle(y, width, containerShape); - - addCompartmentHeaderText(attribTxt, width, rect); - - UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(getFeatureProvider()); - - updateFeature.addSeparatorsToShape(containerShape); - - return containerShape; - } - - private Rectangle addCompartmentRectangle(int y, int width, - ContainerShape containerShape) { - Rectangle rect = Graphiti.getGaService().createRectangle(containerShape); - rect.setFilled(false); - rect.setLineVisible(false); - rect.setHeight(0); - rect.setWidth(width); - rect.setX(0); - rect.setY(y); - containerShape.setActive(true); - return rect; - } - - private void addCompartmentHeaderText(String attribTxt, int width, - Rectangle rect) { - IJPAEditorFeatureProvider fp = getFeatureProvider(); - Text text = UpdateAttributeFeature.addText(fp, rect, attribTxt); - text.getFont().setSize(7); - text.getFont().setItalic(true); - text.getFont().setBold(false); - Graphiti.getGaService().setWidth(text, width); - Graphiti.getGaService().setLocationAndSize(text, 0, 2, width, - 13); - text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER); - text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER); - } - - private void addCompartmentChildren( - ContainerShape containerShape, JavaPersistentType jpt, - String attributeAnnotations) { - List<JavaPersistentAttribute> attributes = new ArrayList<JavaPersistentAttribute>(); - - for (JavaPersistentAttribute attribute : jpt.getAttributes()) { - HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(attribute); - if (annotations.contains(attributeAnnotations)) { - attributes.add(attribute); - } - } - addAttributes(containerShape, attributes); - } - - private void addBasicAttributes(ContainerShape containerShape, JavaPersistentType jpt){ - List<JavaPersistentAttribute> attributes = new ArrayList<JavaPersistentAttribute>(); - - for (JavaPersistentAttribute attribute : jpt.getAttributes()){ - HashSet<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(attribute); - if(!(annotations.contains(JPAEditorConstants.ANNOTATION_ID))&& !(annotations.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY)) && - !(annotations.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE)) && !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY))&& - !(annotations.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) || annotations.isEmpty()){ - attributes.add(attribute); - } - } - addAttributes(containerShape, attributes); - } - - private void addAttributes(ContainerShape entityShape, - List<JavaPersistentAttribute> attributes) { - for (int i = 0; i < attributes.size(); i++) { - JavaPersistentAttribute jpa = attributes.get(i); - addAttribute(jpa, entityShape); - } - } - - public interface IPeUtilFacade { - public ContainerShape createContainerShape(Diagram diagram, boolean b); - } - - public static RoundedRectangle createEntityRectangle(IAddContext context, - ContainerShape entityShape, Diagram diagram) { - - RoundedRectangle entityRectangle = Graphiti.getGaService().createRoundedRectangle( - entityShape, JPAEditorConstants.ENTITY_CORNER_WIDTH, - JPAEditorConstants.ENTITY_CORNER_HEIGHT); - entityRectangle - .setForeground(Graphiti.getGaService().manageColor(diagram, JPAEditorConstants.ENTITY_BORDER_COLOR)); - entityRectangle - .setBackground(Graphiti.getGaService().manageColor(diagram, JPAEditorConstants.ENTITY_BACKGROUND)); - Graphiti.getGaService().setRenderingStyle(entityRectangle.getPictogramElement().getGraphicsAlgorithm(), - PredefinedColoredAreas.getAdaptedGradientColoredAreas(IPredefinedRenderingStyle.BLUE_WHITE_GLOSS_ID)); - entityRectangle.setLineWidth(JPAEditorConstants.ENTITY_BORDER_WIDTH); - entityRectangle.setLineStyle(LineStyle.SOLID); - Graphiti.getGaService().setLocationAndSize(entityRectangle, context - .getX(), context.getY(), - (context.getWidth() == -1) ? JPAEditorConstants.ENTITY_WIDTH - : context.getWidth(), - (context.getHeight() == -1) ? JPAEditorConstants.ENTITY_HEIGHT - : context.getHeight()); - return entityRectangle; - } - - private static class PeUtilFacade implements IPeUtilFacade { - public ContainerShape createContainerShape(Diagram diagram, boolean b) { - return Graphiti.getPeService().createContainerShape(diagram, true); - } - } - - private ContainerShape addHeader(JavaPersistentType addedWrapper, - ContainerShape entityShape, int width) { - - ContainerShape headerIconShape = Graphiti.getPeService().createContainerShape( - entityShape, false); - Rectangle iconRect = Graphiti.getGaService().createRectangle(headerIconShape); - iconRect.setFilled(false); - iconRect.setLineVisible(false); - iconRect.setHeight(JPAEditorConstants.ICON_RECT_HEIGHT); - iconRect.setX(0); - iconRect.setWidth(JPAEditorConstants.HEADER_ICON_RECT_WIDTH); - iconRect.setHeight(JPAEditorConstants.HEADER_ICON_RECT_HEIGHT); - iconRect.setY(0); - Image headerIcon = Graphiti.getGaService().createImage(iconRect, - JPAEditorImageProvider.JPA_ENTITY); - Graphiti.getGaService().setLocationAndSize(headerIcon, - JPAEditorConstants.ICON_HEADER_X, - JPAEditorConstants.ICON_HEADER_Y, - JPAEditorConstants.ICON_WIDTH, - JPAEditorConstants.ICON_HEIGHT); - Graphiti.getPeService().setPropertyValue(headerIconShape, - JPAEditorConstants.PROP_SHAPE_TYPE, ShapeType.ICON.toString()); - - ContainerShape entityHeaderTextShape = Graphiti.getPeService().createContainerShape(entityShape, false); - Graphiti.getPeService() - .setPropertyValue(entityHeaderTextShape, - JPAEditorConstants.PROP_SHAPE_TYPE, ShapeType.HEADER - .toString()); - Rectangle headerRect = Graphiti.getGaService().createRectangle(entityHeaderTextShape); - headerRect.setFilled(false); - headerRect.setLineVisible(false); - headerRect.setWidth(width - JPAEditorConstants.HEADER_TEXT_RECT_WIDTH_REDUCER); - headerRect.setHeight(JPAEditorConstants.HEADER_TEXT_RECT_HEIGHT); - headerRect.setY(2); - headerRect.setX(JPAEditorConstants.HEADER_TEXT_RECT_X); - - String headerTextString = JPAEditorUtil.getText(addedWrapper); - ICompilationUnit cu = getFeatureProvider().getCompilationUnit(addedWrapper); - JPAEditorUtil.becomeWorkingCopy(cu); - headerTextString = JPAEditorUtil.returnSimpleName(headerTextString); - try { - if (cu.hasUnsavedChanges()) { - headerTextString = JPAEditorConstants.HEADER_PREFIX_DIRTY + headerTextString; - } - } catch (JavaModelException e) { - JPADiagramEditorPlugin.logError("Cannot check compilation unit for unsaved changes", e); //$NON-NLS-1$ - } - Text headerTextObj = Graphiti.getGaService().createDefaultText(getDiagram(), headerRect, - headerTextString); - headerTextObj - .setForeground(manageColor(JPAEditorConstants.ENTITY_TEXT_FOREGROUND)); - headerTextObj.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT); - headerTextObj.setVerticalAlignment(Orientation.ALIGNMENT_TOP); - headerTextObj.getFont().setBold(true); - Graphiti.getGaService().setLocationAndSize(headerTextObj, 1, 2, - width, 20); - - return entityHeaderTextShape; - - } - - @SuppressWarnings("deprecation") - private void addAttribute(JavaPersistentAttribute pa, - ContainerShape compartmentShape) { - IJPAEditorFeatureProvider fp = getFeatureProvider(); - fp.putKeyToBusinessObject(fp.getKeyForBusinessObject(pa), pa); - JavaPersistentType jpt = (JavaPersistentType)pa.getParent(); - String key = fp.getKeyForBusinessObject(jpt); - if (fp.getBusinessObjectForKey(key) == null) - fp.putKeyToBusinessObject(key, jpt); - UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(fp); - updateFeature.addAttributes(compartmentShape.getContainer(), pa); - updateFeature = null; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java deleted file mode 100644 index c8c62db78c..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/AddRelationFeature.java +++ /dev/null @@ -1,295 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Kiril Mitov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir.UNI; -import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.MANY_TO_MANY; -import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.MANY_TO_ONE; -import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.ONE_TO_MANY; -import static org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType.ONE_TO_ONE; - -import java.util.List; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IAddBendpointFeature; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IAddConnectionContext; -import org.eclipse.graphiti.features.context.IAddContext; -import org.eclipse.graphiti.features.context.impl.AddBendpointContext; -import org.eclipse.graphiti.features.impl.AbstractAddFeature; -import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageCreator; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtilImpl; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp; -import org.eclipse.swt.graphics.Point; - - -public class AddRelationFeature extends AbstractAddFeature { - - private static final double START_COEFFICIENT = 0.1; - - private IJPAEditorImageCreator imageCreator; - private IJPAEditorUtil jpaEditorUtil; - - public AddRelationFeature(IFeatureProvider fp) { - this(fp, new JPAEditorImageCreator(), new JPAEditorUtilImpl()); - } - - public AddRelationFeature(IFeatureProvider fp, - IJPAEditorImageCreator imageCreator, - IJPAEditorUtil jpaEditorUtil) { - super(fp); - this.imageCreator = imageCreator; - this.jpaEditorUtil = jpaEditorUtil; - } - - public PictogramElement add(IAddContext context) { - final IAddConnectionContext addConContext = (IAddConnectionContext) context; - final IRelation relation = (IRelation) context.getNewObject(); - final Diagram diagram = getDiagram(); - final Wrp wrp = new Wrp(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram); - RecordingCommand rc = new RecordingCommand(ted) { - protected void doExecute() { - FreeFormConnection connection = createConnection(addConContext, relation, diagram); - imageCreator.createConnectionLine(diagram, connection); - getFeatureProvider().putKeyToBusinessObject(relation.getId(), relation); - link(connection, relation); - layoutPictogramElement(connection); - wrp.setObj(connection); - } - }; - try { - ted.getCommandStack().execute(rc); - } catch (Exception e){ - - } - - return (PictogramElement)wrp.getObj(); - } - - private FreeFormConnection createConnection(IAddConnectionContext addConContext, IRelation relation, - final Diagram diagram) { - FreeFormConnection connection = getFeatureProvider().getPeUtil().createFreeFormConnection(diagram); - connection.setStart(addConContext.getSourceAnchor()); - connection.setEnd(addConContext.getTargetAnchor()); - connection.setVisible(true); - connection.setActive(true); - List<Point> points = jpaEditorUtil.createBendPointList(connection, relation.getOwner() == relation.getInverse()); - for (int i = 0; i < points.size(); i++) { - Point p = points.get(i); - AddBendpointContext ctx = new AddBendpointContext(connection, p.x, p.y, i); - IAddBendpointFeature ft =getFeatureProvider().getAddBendpointFeature(ctx); - ft.addBendpoint(ctx); - } - addDecorators(connection, relation); - addTextDecorators(connection, relation); - return connection; - } - - private void addDecorators(FreeFormConnection connection, IRelation relation) { - RelDir direction = relation.getRelDir(); - RelType type = relation.getRelType(); - if (ONE_TO_ONE.equals(type)) { - addOneToOneDecorator(connection, direction, relation); - } else if (ONE_TO_MANY.equals(type) && UNI.equals(direction)) { - addOneToManyDecorator(connection, relation); - } else if (MANY_TO_ONE.equals(type)) { - addManyToOneDecorator(connection, direction, relation); - } else if (MANY_TO_MANY.equals(type)) { - addManyToManyDecorator(connection, direction, relation); - } - } - - private void addTextDecorators(FreeFormConnection connection, IRelation relation) { - RelDir direction = relation.getRelDir(); - RelType type = relation.getRelType(); - if (ONE_TO_ONE.equals(type)) { - addOneToOneTextDecorator(connection, direction, relation); - } else if (ONE_TO_MANY.equals(type) && UNI.equals(direction)) { - addOneToManyTextDecorator(connection, relation); - } else if (MANY_TO_ONE.equals(type)) { - addManyToOneTextDecorator(connection, direction, relation); - } else if (MANY_TO_MANY.equals(type)) { - addManyToManyTextDecorator(connection, direction, relation); - } - } - - - private void addOneToOneDecorator(FreeFormConnection c, RelDir direction, IRelation rel) { - double startCoefficient = START_COEFFICIENT; - double endCoefficient = 1.0 - startCoefficient; - int len = JPAEditorUtil.calcConnectionLength(c); - if (UNI.equals(direction)) { - ConnectionDecorator d = imageCreator.createArrowConnectionDecorator(c, endCoefficient); - Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0); - } - } - - private void addOneToManyDecorator(FreeFormConnection c, IRelation rel) { - double startCoefficient = START_COEFFICIENT; - double endCoefficient = 1.0 - startCoefficient; - int len = JPAEditorUtil.calcConnectionLength(c); - ConnectionDecorator d = imageCreator.createManyEndWithArrowDecorator(c, endCoefficient); - Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0); - } - - private void addManyToOneDecorator(FreeFormConnection c, RelDir direction, IRelation rel) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getOwner()); - double startCoefficient = START_COEFFICIENT; - double endCoefficient = 1.0 - startCoefficient; - int len = JPAEditorUtil.calcConnectionLength(c); - ConnectionDecorator d1 = imageCreator.createManyStartDecorator(c, startCoefficient); - Graphiti.getGaService().setLocation(d1.getGraphicsAlgorithm(),Math.round(len/10), 0); - if (UNI.equals(direction)) { - ConnectionDecorator d2 = imageCreator.createArrowConnectionDecorator(c, endCoefficient); - Graphiti.getGaService().setLocation(d2.getGraphicsAlgorithm(),Math.round(-len/10), 0); - } - } - - private void addManyToManyDecorator(FreeFormConnection c, RelDir direction, IRelation rel) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getOwner()); - double startCoefficient = START_COEFFICIENT; - double endCoefficient = 1.0 - startCoefficient; - int len = JPAEditorUtil.calcConnectionLength(c); - ConnectionDecorator d1 = imageCreator.createManyStartDecorator(c, startCoefficient); - Graphiti.getGaService().setLocation(d1.getGraphicsAlgorithm(),Math.round(len/10), 0); - if (UNI.equals(direction)) { - ConnectionDecorator d = imageCreator.createManyEndWithArrowDecorator(c, endCoefficient); - Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0); - } else { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getInverse()); - ConnectionDecorator d = imageCreator.createManyEndDecorator(c, endCoefficient); - Graphiti.getGaService().setLocation(d.getGraphicsAlgorithm(),Math.round(-len/10), 0); - } - } - - - - - - - private void addOneToOneTextDecorator(FreeFormConnection c, RelDir direction, IRelation rel) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getOwner()); - OneToOneAnnotation a = null; - Boolean optional; - boolean isOptional = false; - if (RelDir.UNI.equals(direction)) { - isOptional = true; - } else { - JavaPersistentAttribute inverse = rel.getInverse().getAttributeNamed(rel.getInverseAttributeName()); - JpaArtifactFactory.instance().refreshEntityModel(null, (JavaPersistentType)inverse.getParent()); - JavaAttributeMapping mapping = inverse.getMapping(); - a = (OneToOneAnnotation)mapping.getMappingAnnotation(); - if (a != null) { - optional = a.getOptional(); - isOptional = (optional == null) ? true : optional.booleanValue(); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? JPAEditorConstants.CARDINALITY_ZERO_ONE : JPAEditorConstants.CARDINALITY_ONE, 0.0); - } - } - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getOwner()); - JavaPersistentAttribute owner = rel.getOwner().getAttributeNamed(rel.getOwnerAttributeName()); - owner.update(); - JavaAttributeMapping mapping = owner.getMapping(); - a = (OneToOneAnnotation)mapping.getMappingAnnotation(); - if (a == null) - return; - optional = a.getOptional(); - isOptional = (optional == null) ? true : optional.booleanValue(); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? JPAEditorConstants.CARDINALITY_ZERO_ONE : JPAEditorConstants.CARDINALITY_ONE, 1.0); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0); - if (!UNI.equals(direction)) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getInverse()); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getInverseAttributeName(), 1.0); - } - } - - private void addOneToManyTextDecorator(FreeFormConnection c, IRelation rel) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getOwner()); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_ONE, 0.0); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_N, 1.0); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0); - } - - private void addManyToOneTextDecorator(FreeFormConnection c, RelDir direction, IRelation rel) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getOwner()); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_N, 0.0); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0); - JavaPersistentAttribute owner = rel.getOwner().getAttributeNamed(rel.getOwnerAttributeName()); - JavaAttributeMapping mapping = owner.getMapping(); - ManyToOneAnnotation a = (ManyToOneAnnotation)mapping.getMappingAnnotation(); - if (a == null) - return; - Boolean optional = a.getOptional(); - boolean isOptional = (optional == null) ? true : optional.booleanValue(); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, isOptional ? - JPAEditorConstants.CARDINALITY_ZERO_ONE : - JPAEditorConstants.CARDINALITY_ONE, 1.0); - if (!UNI.equals(direction)) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getInverse()); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getInverseAttributeName(), 1.0); - } - } - - private void addManyToManyTextDecorator(FreeFormConnection c, RelDir direction, IRelation rel) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getOwner()); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_N, 0.0); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, JPAEditorConstants.CARDINALITY_ZERO_N, 1.0); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getOwnerAttributeName(), 0.0); - if (!UNI.equals(direction)) { - JpaArtifactFactory.instance().refreshEntityModel(null, rel.getInverse()); - imageCreator.createCardinalityConnectionDecorator(getDiagram(), c, rel.getInverseAttributeName(), 1.0); - } - } - - - - - - - public boolean canAdd(IAddContext context) { - if (context instanceof IAddConnectionContext && context.getNewObject() instanceof IRelation) { - return true; - } - return false; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - -} - diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java deleted file mode 100644 index c8779ccdda..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickAddAttributeButtonFeature.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICreateContext; -import org.eclipse.graphiti.features.impl.AbstractCreateFeature; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; - - -public class ClickAddAttributeButtonFeature extends AbstractCreateFeature { - - public ClickAddAttributeButtonFeature(IFeatureProvider provider) { - super(provider, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public boolean canExecute(IContext context) { - return true; - } - - public boolean canUndo(IContext context) { - return false; - } - - public boolean canCreate(ICreateContext context) { - return true; - } - - public Object[] create(ICreateContext context) { - ContainerShape entityShape = context.getTargetContainer(); - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(entityShape); - String newAttrName = JpaArtifactFactory.instance().createNewAttribute(jpt, false, getFeatureProvider()); - JpaArtifactFactory.instance().refreshEntityModel(getFeatureProvider(), jpt); - JavaPersistentAttribute newAttr = jpt.getAttributeNamed(newAttrName); - int cnt = 0; - while ((newAttr == null) && (cnt < 25)) { - newAttr = jpt.getAttributeNamed(newAttrName); - if (newAttr == null) { - try { - Thread.sleep(200); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError("Thread sleep interrupted", e); //$NON-NLS-1$ - } - } - cnt++; - } - getFeatureProvider().addAddIgnore((JavaPersistentType)newAttr.getParent(), newAttr.getName()); - addGraphicalRepresentation(context, newAttr); - getFeatureProvider().getDirectEditingInfo().setActive(true); - - IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite(); - ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt); - getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws); - - return new Object[] {newAttr}; - } - - public boolean isAvailable(IContext context) { - return true; - } - - public String getName() { - return JPAEditorMessages.ClickAddAttributeButtonFeature_createAttributeButtonLabel; - } - - public String getDescription() { - return JPAEditorMessages.ClickAddAttributeButtonFeature_createAttributeButtonDescription; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java deleted file mode 100644 index 5f117af542..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.text.MessageFormat; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IDeleteContext; -import org.eclipse.graphiti.internal.features.context.impl.base.PictogramElementContext; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - - -@SuppressWarnings("restriction") -public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature { - - private String attrName = ""; //$NON-NLS-1$ - - public ClickRemoveAttributeButtonFeature(IFeatureProvider provider) { - super(provider); - } - - protected String getQuestionToUser() { - return MessageFormat.format(JPAEditorMessages.ClickRemoveAttributeButtonFeature_deleteAttributeQuestion, new Object[] {attrName}); - } - - - public boolean canUndo(IContext context) { - return false; - } - - private String getAttrName(ContainerShape textShape) { - String txt = ((Text)(textShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0))).getValue(); - String attrName = txt.substring(txt.indexOf(':') + 1); - attrName = attrName.trim(); - return attrName; - } - - private void deleteAttribute(ContainerShape pe, String attrName) { - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(pe.getContainer().getContainer()); - JpaArtifactFactory.instance().deleteAttribute(jpt, attrName, getFeatureProvider()); - } - - public void delete(IDeleteContext context) { - delete(context, true); - } - - @Override - public void preDelete(IDeleteContext context) { - super.preDelete(context); - } - - public void delete(IDeleteContext context, boolean haveToAsk) { - PictogramElementContext ctx = (PictogramElementContext)context; - ContainerShape textShape = (ContainerShape)ctx.getPictogramElement(); - if ((textShape == null) || textShape.getGraphicsAlgorithm() == null) - return; - String attrName = getAttrName(textShape); - this.attrName = attrName; - if (haveToAsk) { - if (!getUserDecision(context)) { - return; - } - } - - preDelete(context); - if (textShape.getGraphicsAlgorithm() == null){ - return; - } - deleteAttribute(textShape, attrName); - } - - - protected void deleteBusinessObjects(Object[] businessObjects) { - if (businessObjects != null) { - for (Object bo : businessObjects) { - deleteBusinessObject(bo); - } - } - } - - public boolean isAvailable(IContext context) { - return true; - } - - public String getName() { - return JPAEditorMessages.ClickRemoveAttributeButtonFeature_createAttributeButtonlabel; - } - - public String getDescription() { - return JPAEditorMessages.ClickRemoveAttributeButtonFeature_createAttributeButtonDescription; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseAllEntitiesFeature.java deleted file mode 100644 index 15bbd93ea9..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseAllEntitiesFeature.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.features.custom.ICustomFeature; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class CollapseAllEntitiesFeature extends AbstractCustomFeature implements ICustomFeature{ - - public CollapseAllEntitiesFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram(); - final EList<Shape> entShapes = diagram.getChildren(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - for (final PictogramElement el : entShapes) { - String collapseFeatures = Graphiti.getPeService().getPropertyValue(el, JPAEditorConstants.COLLAPSE_FEATURES); - if (collapseFeatures == null) { - GraphicsAlgorithm algo = el.getGraphicsAlgorithm(); - algo.setHeight(JPAEditorConstants.ENTITY_MIN_HEIGHT); - Graphiti.getPeService().setPropertyValue(el, JPAEditorConstants.COLLAPSE_FEATURES, String.valueOf(JPAEditorConstants.ENTITY_MIN_HEIGHT)); - JPAEditorUtil.rearrangeAllConnections((ContainerShape) el, getFeatureProvider(), false); - } - } - } - }); - - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - @Override - public boolean isAvailable(IContext context) { - return true; - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseAllEntitiesMenuItem; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseCompartmentShapeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseCompartmentShapeFeature.java deleted file mode 100644 index c0fb9c44d8..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseCompartmentShapeFeature.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Petya Sabeva - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class CollapseCompartmentShapeFeature extends AbstractCustomFeature{ - - public CollapseCompartmentShapeFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - PictogramElement el = context.getPictogramElements()[0]; - - final ContainerShape containerShape = (ContainerShape) el; - final ContainerShape entityShape = containerShape.getContainer(); - - final GraphicsAlgorithm algo = el.getGraphicsAlgorithm(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(algo); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - algo.setHeight(JPAEditorConstants.COMPARTMENT_MIN_HEIGHT); - GraphicsUpdater.updateEntityShape(entityShape); - GraphicsUpdater.setCollapsed(containerShape, true); - JPAEditorUtil.rearrangeAllConnections(entityShape, getFeatureProvider(), false); - } - }); - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - @Override - public boolean isAvailable(IContext context) { - boolean ret = false; - if (context instanceof ICustomContext) { - PictogramElement[] pes = ((ICustomContext) context).getPictogramElements(); - if (pes != null && pes.length > 0) { - boolean collapsePossible = false; - for (int i = 0; i < pes.length; i++) { - PictogramElement pe = pes[i]; - Object bo = getBusinessObjectForPictogramElement(pe); - if (bo != null) { - return false; - } - if (!collapsePossible) { - if(!GraphicsUpdater.isCollapsed((ContainerShape)pe)) { - collapsePossible = true; - } - } - } - if (collapsePossible) { - return true; - } - } - } - return ret; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseEntityFeature.java deleted file mode 100644 index ac695dde29..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CollapseEntityFeature.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Petya Sabeva - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.features.custom.ICustomFeature; -import org.eclipse.graphiti.mm.Property; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class CollapseEntityFeature extends AbstractCustomFeature implements ICustomFeature{ - - public CollapseEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - final PictogramElement el = context.getPictogramElements()[0]; - - final GraphicsAlgorithm algo = el.getGraphicsAlgorithm(); - - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(algo); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - algo.setHeight(JPAEditorConstants.ENTITY_MIN_HEIGHT); - Graphiti.getPeService().setPropertyValue(el, JPAEditorConstants.COLLAPSE_FEATURES, String.valueOf(JPAEditorConstants.ENTITY_MIN_HEIGHT)); - JPAEditorUtil.rearrangeAllConnections((ContainerShape) el, getFeatureProvider(), false); - } - }); - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - @Override - public boolean isAvailable(IContext context) { - boolean ret = false; - if (context instanceof ICustomContext) { - PictogramElement[] pes = ((ICustomContext) context).getPictogramElements(); - if (pes != null && pes.length > 0) { - boolean collapsePossible = false; - for (int i = 0; i < pes.length; i++) { - PictogramElement pe = pes[i]; - Object bo = getBusinessObjectForPictogramElement(pe); - if (!(bo instanceof JavaPersistentType)) { - return false; - } - if (!collapsePossible) { - Property property = Graphiti.getPeService().getProperty(pe, JPAEditorConstants.COLLAPSE_FEATURES); - if (property == null) { - collapsePossible = true; - } - } - } - if (collapsePossible) { - return true; - } - } - } - return ret; - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseEntityMenuItem; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java deleted file mode 100644 index 284219f0f5..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFeature.java +++ /dev/null @@ -1,178 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICreateContext; -import org.eclipse.graphiti.features.impl.AbstractCreateFeature; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditor; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; - - -public class CreateJPAEntityFeature extends AbstractCreateFeature { - - private IPreferenceStore jpaPreferenceStore = JPADiagramEditorPlugin.getDefault().getPreferenceStore(); - private boolean isMappedSuperclassChild; - private String mappedSuperclassName; - private String mappedSuperclassPackage; - private boolean hasPrimarykey; - - - public CreateJPAEntityFeature(IFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateJPAEntityFeature_jpaEntityFeatureName, JPAEditorMessages.CreateJPAEntityFeature_jpaEntityFeatureDescription); - } - - public CreateJPAEntityFeature(IFeatureProvider fp, - boolean isMappedSuperclassChild, String mappedSuperclassName, - String mappedSuperClassPackage) { - this(fp, isMappedSuperclassChild, mappedSuperclassName, - mappedSuperClassPackage, false); - } - - public CreateJPAEntityFeature(IFeatureProvider fp, - boolean isMappedSuperclassChild, String mappedSuperclassName) { - this(fp, isMappedSuperclassChild, mappedSuperclassName, null, false); - } - - public CreateJPAEntityFeature(IFeatureProvider fp, - boolean isMappedSuperclassChild, String mappedSuperclassName, - String mappedSuperClassPackage, boolean hasPrimaryKey) { - this(fp); - this.isMappedSuperclassChild = isMappedSuperclassChild; - this.mappedSuperclassName = mappedSuperclassName; - this.mappedSuperclassPackage = mappedSuperClassPackage; - this.hasPrimarykey = hasPrimaryKey; - } - - - public boolean canCreate(ICreateContext context) { - return context.getTargetContainer() instanceof Diagram; - } - - @SuppressWarnings("restriction") - public Object[] create(ICreateContext context) { - List<Shape> shapes = this.getFeatureProvider().getDiagramTypeProvider().getDiagram().getChildren(); - IProject targetProject = null; - JpaProject jpaProject = null; - if ((shapes == null) || (shapes.size() == 0)) { - jpaProject = getTargetJPAProject(); - targetProject = jpaProject.getProject(); - } else { - Shape sh = shapes.get(0); - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(sh); - if (jpt == null) - return new Object[] {}; - jpaProject = jpt.getJpaProject(); - targetProject = jpaProject.getProject(); - } - String entityName = getFeatureProvider().getJPAEditorUtil(). - generateUniqueEntityName(jpaProject, - JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()), - getFeatureProvider()); - - if(!JPAEditorUtil.checkIsSetPersistenceProviderLibrary(jpaProject)){ - Shell shell = JPADiagramEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(); - IStatus status = new Status(IStatus.ERROR, JPADiagramEditor.ID, JPAEditorMessages.CreateJPAEntityFeature_createEntityErrorStatusMsg); - ErrorDialog.openError(shell, JPAEditorMessages.CreateJPAEntityFeature_createEntityErrorMsgTitle, - JPAEditorMessages.CreateJPAEntityFeature_createEntityErrorMsg, status); - return new Object[] {}; - } - - if (!JptJpaCorePlugin.discoverAnnotatedClasses(targetProject)) { - JPAEditorUtil.createRegisterEntityInXMLJob(jpaProject, entityName); - } - - try { - this.getFeatureProvider().getJPAEditorUtil().createEntityInProject(targetProject, entityName, jpaPreferenceStore, isMappedSuperclassChild, mappedSuperclassName, mappedSuperclassPackage, hasPrimarykey); - } catch (Exception e1) { - JPADiagramEditorPlugin.logError("Cannot create an entity in the project " + targetProject.getName(), e1); //$NON-NLS-1$ - } - - - try { - jpaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); - } catch (CoreException e1) { - JPADiagramEditorPlugin.logError("Cannot refresh the project", e1); //$NON-NLS-1$ - } - - ListIterator<PersistenceUnit> lit = jpaProject.getRootContextNode().getPersistenceXml().getPersistence().getPersistenceUnits().iterator(); - PersistenceUnit pu = lit.next(); - JavaPersistentType jpt = (JavaPersistentType)pu.getPersistentType(entityName); - - int cnt = 0; - while ((jpt == null) && (cnt < 25)) { - try { - Thread.sleep(200); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError("Thread sleep interrupted", e); //$NON-NLS-1$ - } - jpt = (JavaPersistentType)pu.getPersistentType(entityName); - cnt++; - } - - if (jpt != null) { - addGraphicalRepresentation(context, jpt); - IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite(); - ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt); - getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws); - return new Object[] { jpt }; - } else { - JPADiagramEditorPlugin.logError("The JPA entity " + entityName + " could not be created", new Exception()); //$NON-NLS-1$ //$NON-NLS-2$ - } - return new Object[] {}; - } - - @Override - public String getCreateImageId() { - return JPAEditorImageProvider.ADD_JPA_ENTITY; - } - - @Override - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - private JpaProject getTargetJPAProject() { - return getFeatureProvider().getMoinIntegrationUtil().getProjectByDiagram(getDiagram()); - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java deleted file mode 100644 index 620654b971..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateJPAEntityFromMappedSuperclassFeature.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICreateContext; -import org.eclipse.graphiti.features.impl.AbstractCreateFeature; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - - -public class CreateJPAEntityFromMappedSuperclassFeature extends - AbstractCreateFeature { - private IPreferenceStore jpaPreferenceStore = JPADiagramEditorPlugin - .getDefault().getPreferenceStore(); - - public CreateJPAEntityFromMappedSuperclassFeature(IFeatureProvider fp) { - super( - fp, - JPAEditorMessages.CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName, - JPAEditorMessages.CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureDescription); - } - - public boolean canCreate(ICreateContext context) { - return context.getTargetContainer() instanceof Diagram; - } - - public Object[] create(ICreateContext context) { - List<Shape> shapes = this.getFeatureProvider().getDiagramTypeProvider() - .getDiagram().getChildren(); - IProject targetProject = null; - JpaProject jpaProject = null; - if ((shapes == null) || (shapes.size() == 0)) { - jpaProject = getTargetJPAProject(); - targetProject = jpaProject.getProject(); - } else { - Shape sh = shapes.get(0); - JavaPersistentType jpt = (JavaPersistentType) getFeatureProvider() - .getBusinessObjectForPictogramElement(sh); - if (jpt == null) - return new Object[] {}; - jpaProject = jpt.getJpaProject(); - targetProject = jpaProject.getProject(); - } - - String mappedSuperclassName = getFeatureProvider() - .getJPAEditorUtil() - .generateUniqueMappedSuperclassName( - jpaProject, - JPADiagramPropertyPage.getDefaultPackage(jpaProject.getProject()), - getFeatureProvider()); - - if (!JptJpaCorePlugin.discoverAnnotatedClasses(jpaProject.getProject())) { - JPAEditorUtil.createRegisterEntityInXMLJob(jpaProject, mappedSuperclassName); - } - - - try { - this.getFeatureProvider() - .getJPAEditorUtil() - .createEntityFromMappedSuperclassInProject(targetProject, - mappedSuperclassName, jpaPreferenceStore); - } catch (Exception e1) { - JPADiagramEditorPlugin.logError("Cannot create an entity in the project " + targetProject.getName(), e1); //$NON-NLS-1$ - } - - CreateJPAEntityFeature createEntityFeature = new CreateJPAEntityFeature( - getFeatureProvider(), true, mappedSuperclassName); - return createEntityFeature.create(context); - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ADD_INHERITED_ENTITY; - } - - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - private JpaProject getTargetJPAProject() { - return getFeatureProvider().getMoinIntegrationUtil() - .getProjectByDiagram(getDiagram()); - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java deleted file mode 100644 index 6e44389998..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyBiDirRelationFeature.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class CreateManyToManyBiDirRelationFeature extends - CreateManyToManyRelationFeature { - - public CreateManyToManyBiDirRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName, - JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyUniDirFeatureDescription); - } - - @Override - public ManyToManyBiDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target) { - JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source)); - JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target)); - - String ownerAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse)); - String nameWithNonCapitalLetter = ownerAttributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) - nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(ownerAttributeName); - String ownerAttributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - - String inverseAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(owner)); - String nameWithNonCapitalLetter2 = inverseAttributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(inverse)) - nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName); - String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2); - - ManyToManyBiDirRelation rel = new ManyToManyBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, - getFeatureProvider().getCompilationUnit(owner), - getFeatureProvider().getCompilationUnit(inverse)); - return rel; - - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_MANY_TO_MANY_2_DIR; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java deleted file mode 100644 index 79d040fb7b..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyRelationFeature.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; - - -abstract class CreateManyToManyRelationFeature - extends CreateRelationFeature { - - public CreateManyToManyRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java deleted file mode 100644 index 1e58fd51f1..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToManyUniDirRelationFeature.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class CreateManyToManyUniDirRelationFeature extends - CreateManyToManyRelationFeature { - - public CreateManyToManyUniDirRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName, - JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureDescription); - } - - @Override - public ManyToManyUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target) { - JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source)); - JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target)); - - String attributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse)); - String nameWithNonCapitalLetter = attributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) - nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName); - String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - ManyToManyUniDirRelation relation = new ManyToManyUniDirRelation(fp, owner, inverse, attributeText, true, - getFeatureProvider().getCompilationUnit(owner), - getFeatureProvider().getCompilationUnit(inverse)); - return relation; - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_MANY_TO_MANY_1_DIR; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java deleted file mode 100644 index ceeb529747..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneBiDirRelationFeature.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class CreateManyToOneBiDirRelationFeature extends - CreateManyToOneRelationFeature { - - public CreateManyToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName, - JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureDescription); - } - - @Override - public ManyToOneBiDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, - PictogramElement target) { - JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source)); - JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target)); - - String ownerAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse)); - String nameWithNonCapitalLetter = ownerAttributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) - nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(ownerAttributeName); - String ownerAttributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - - String inverseAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(owner)); - String nameWithNonCapitalLetter2 = inverseAttributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(inverse)) - nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName); - String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2); - - ManyToOneBiDirRelation rel = new ManyToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, - getFeatureProvider().getCompilationUnit(owner), - getFeatureProvider().getCompilationUnit(inverse)); - return rel; - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_MANY_TO_ONE_2_DIR; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java deleted file mode 100644 index 1f1c9eca1c..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneRelationFeature.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; - -abstract class CreateManyToOneRelationFeature - extends CreateRelationFeature { - - public CreateManyToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java deleted file mode 100644 index fafc150fd4..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateManyToOneUniDirRelationFeature.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class CreateManyToOneUniDirRelationFeature extends - CreateManyToOneRelationFeature { - - public CreateManyToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName, - JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureDescription); - } - - @Override - public ManyToOneUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, PictogramElement target) { - JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source)); - JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target)); - - String attributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse)); - String nameWithNonCapitalLetter = attributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) - nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName); - String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - ManyToOneUniDirRelation relation = new ManyToOneUniDirRelation(fp, owner, inverse, attributeText, true, - getFeatureProvider().getCompilationUnit(owner), - getFeatureProvider().getCompilationUnit(inverse)); - return relation; - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_MANY_TO_ONE_1_DIR; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java deleted file mode 100644 index c3ec2d1aac..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyRelationFeature.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; - -abstract class CreateOneToManyRelationFeature - extends CreateRelationFeature { - - public CreateOneToManyRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java deleted file mode 100644 index 2eb3367f5a..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToManyUniDirRelationFeature.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToManyUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class CreateOneToManyUniDirRelationFeature extends - CreateOneToManyRelationFeature { - - public CreateOneToManyUniDirRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName, - JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureDescription); - } - - @Override - public OneToManyUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, - PictogramElement target) { - JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source)); - JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target)); - - String attributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse)); - String nameWithNonCapitalLetter = attributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) - nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(attributeName); - - String attributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - OneToManyUniDirRelation relation = new OneToManyUniDirRelation(fp, owner, inverse, attributeText, true, - getFeatureProvider().getCompilationUnit(owner), - getFeatureProvider().getCompilationUnit(inverse)); - return relation; - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_ONE_TO_MANY_1_DIR; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java deleted file mode 100644 index 3a65a5dbcf..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneBiDirRelationFeature.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneBiDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class CreateOneToOneBiDirRelationFeature extends CreateOneToOneRelationFeature { - - public CreateOneToOneBiDirRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName, - JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureDescription); - } - - @Override - public OneToOneBiDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, - PictogramElement target) { - JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source)); - JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target)); - - String ownerAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse)); - String nameWithNonCapitalLetter = ownerAttributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) - nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(ownerAttributeName); - String ownerAttributeText = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - - String inverseAttributeName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(owner)); - String nameWithNonCapitalLetter2 = inverseAttributeName; - if (JpaArtifactFactory.instance().isMethodAnnotated(inverse)) - nameWithNonCapitalLetter2 = JPAEditorUtil.produceValidAttributeName(inverseAttributeName); - String inverseAttributeText = JPAEditorUtil.produceUniqueAttributeName(inverse, ownerAttributeText, nameWithNonCapitalLetter2); - - OneToOneBiDirRelation rel = new OneToOneBiDirRelation(fp, owner, inverse, ownerAttributeText, inverseAttributeText, true, - getFeatureProvider().getCompilationUnit(owner), - getFeatureProvider().getCompilationUnit(inverse)); - return rel; - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_ONE_TO_ONE_2_DIR; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java deleted file mode 100644 index f4b9fea728..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneRelationFeature.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; - -abstract class CreateOneToOneRelationFeature - extends CreateRelationFeature { - - public CreateOneToOneRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); - } -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java deleted file mode 100644 index dae132dc57..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateOneToOneUniDirRelationFeature.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - - -public class CreateOneToOneUniDirRelationFeature extends CreateOneToOneRelationFeature { - - public CreateOneToOneUniDirRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp, JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName, - JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureDescription); - } - - @Override - public OneToOneUniDirRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, - PictogramElement target) { - - JavaPersistentType owner = (JavaPersistentType)(getBusinessObjectForPictogramElement(source)); - JavaPersistentType inverse = (JavaPersistentType)(getBusinessObjectForPictogramElement(target)); - - String name = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(inverse)); - String nameWithNonCapitalLetter = name; - if (JpaArtifactFactory.instance().isMethodAnnotated(owner)) - nameWithNonCapitalLetter = JPAEditorUtil.produceValidAttributeName(name); - String attribTxt = JPAEditorUtil.produceUniqueAttributeName(owner, nameWithNonCapitalLetter); - OneToOneUniDirRelation res = new OneToOneUniDirRelation(fp, owner, inverse, attribTxt, true, - getFeatureProvider().getCompilationUnit(owner), - getFeatureProvider().getCompilationUnit(inverse)); - return res; - } - - public String getCreateImageId() { - return JPAEditorImageProvider.ICON_ONE_TO_ONE_1_DIR; - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java deleted file mode 100644 index 752b5bc4c6..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/CreateRelationFeature.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.context.ICreateConnectionContext; -import org.eclipse.graphiti.features.context.impl.AddConnectionContext; -import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature; -import org.eclipse.graphiti.mm.pictograms.Anchor; -import org.eclipse.graphiti.mm.pictograms.Connection; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation; - - -abstract public class CreateRelationFeature extends AbstractCreateConnectionFeature { - - public CreateRelationFeature(IJPAEditorFeatureProvider fp, String name, String description) { - super(fp, name, description); - } - - public boolean canCreate(ICreateConnectionContext context) { - JavaPersistentType source = (JavaPersistentType)getPersistentType(context.getSourceAnchor()); - JavaPersistentType target = (JavaPersistentType)getPersistentType(context.getTargetAnchor()); - if (source != null && target != null) { - return true; - } - return false; - } - - public boolean canStartConnection(ICreateConnectionContext context) { - if (getPersistentType(context.getSourceAnchor()) != null) - return true; - return false; - } - - public Connection create(ICreateConnectionContext context) { - Connection newConnection = null; - PersistentType source = getPersistentType(context.getSourceAnchor()); - PersistentType target = getPersistentType(context.getTargetAnchor()); - if (source != null && target != null) { - AbstractRelation rel = createRelation(getFeatureProvider(), context.getSourceAnchor().getParent(), - context.getTargetAnchor().getParent()); - AddConnectionContext addContext = - new AddConnectionContext(context.getSourceAnchor(), context - .getTargetAnchor()); - addContext.setNewObject(rel); - newConnection = - (Connection) getFeatureProvider().addIfPossible(addContext); - } - return newConnection; - } - - /** - * Returns the PersistentType class belonging to the anchor, or null if not available. - */ - protected PersistentType getPersistentType(Anchor anchor) { - if (anchor != null) { - Object refObject = - getBusinessObjectForPictogramElement(anchor.getParent()); - if (refObject instanceof PersistentType) { - return (PersistentType) refObject; - } - } - return null; - } - - - /** - * Creates a new OneToOneRelation between two PersistentType classes. - */ - abstract protected AbstractRelation createRelation(IJPAEditorFeatureProvider fp, PictogramElement source, - PictogramElement target); - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java deleted file mode 100644 index 7b81077a2b..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteJPAEntityFeature.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.text.MessageFormat; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IDeleteContext; -import org.eclipse.graphiti.features.context.IMultiDeleteInfo; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.ui.PlatformUI; - - -public class DeleteJPAEntityFeature extends DefaultDeleteFeature { - - private String entityClassName = null; - private String entityName = null; - public DeleteJPAEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public void delete(final IDeleteContext context) { - PictogramElement pe = context.getPictogramElement(); - - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(pe); - entityClassName = jpt.getName(); - entityName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(jpt)); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - deleteEl(context); - } - }); - - } - - public void deleteEl(IDeleteContext context){ - super.delete(context); - } - - protected void deleteBusinessObject(Object bo) { - JavaPersistentType jpt = null; - if (bo instanceof JavaPersistentType) { - jpt = (JavaPersistentType) bo; - - - JpaProject jpaProject = jpt.getJpaProject(); - String name = jpt.getName(); - - - JpaArtifactFactory.instance().forceSaveEntityClass(jpt, getFeatureProvider()); - JpaArtifactFactory.instance().deleteEntityClass(jpt, getFeatureProvider()); - if (!JptJpaCorePlugin.discoverAnnotatedClasses(jpt.getJpaProject().getProject())) { - JPAEditorUtil.createUnregisterEntityFromXMLJob(jpaProject, name); - } - - } - } - - public String getQuestionToUser() { - return MessageFormat.format(JPAEditorMessages.DeleteJPAEntityFeature_deleteJPAEntityQuestion, entityName, entityClassName); - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - protected boolean getUserDecision(IDeleteContext context) { - String msg = ""; //$NON-NLS-1$ - IMultiDeleteInfo multiDeleteInfo = context.getMultiDeleteInfo(); - if (multiDeleteInfo != null) { - msg = JPAEditorMessages.DeleteJPAEntityFeature_deleteJPAEntitiesQuestion; - } else { - if (entityClassName != null && entityClassName.length() > 0) { - msg = MessageFormat.format(JPAEditorMessages.DeleteJPAEntityFeature_deleteJPAEntityQuestion, entityName, entityClassName); - } - } - return MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), - JPAEditorMessages.DeleteFeature_deleteConfirm, msg); - } - - - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java deleted file mode 100644 index 89e18ce7a1..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DeleteRelationFeature.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IDeleteContext; -import org.eclipse.graphiti.features.context.impl.DeleteContext; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.UnidirectionalRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.PlatformUI; - - -public class DeleteRelationFeature extends DefaultDeleteFeature{ - - private static IJPAEditorUtil ut = null; - - public DeleteRelationFeature(IJPAEditorFeatureProvider fp) { - super(fp); - ut = fp.getJPAEditorUtil(); - } - - public boolean canDelete(IDeleteContext context) { - return true; - } - - public boolean isAvailable(IContext context) { - return true; - } - - public boolean canExecute(IContext context) { - return true; - } - - protected String getQuestionToUser() { - return JPAEditorMessages.DeleteRelationFeature_deleteRelationQuestion; - } - - public void delete(IDeleteContext context) { - PictogramElement pe = context.getPictogramElement(); - Object businessObjectForPictogramElement = getBusinessObjectForPictogramElement(pe); - if (businessObjectForPictogramElement != null) { - if (!getUserDecision(context)) { - return; - } - } - - preDelete(context); - AbstractRelation rel = (AbstractRelation)businessObjectForPictogramElement; - - if (rel instanceof UnidirectionalRelation) { - UnidirectionalRelation relation = (UnidirectionalRelation)rel; - ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider()); - JavaPersistentAttribute attribute = relation.getAnnotatedAttribute(); - PictogramElement textShape = getFeatureProvider().getPictogramElementForBusinessObject(attribute); - IDeleteContext delCtx = new DeleteContext(textShape); - feat.delete(delCtx, false); - } - - if (rel instanceof BidirectionalRelation) { - BidirectionalRelation relation = (BidirectionalRelation)(rel); - ClickRemoveAttributeButtonFeature feat = new ClickRemoveAttributeButtonFeature(getFeatureProvider()); - - JavaPersistentAttribute ownerAttribute = relation.getOwnerAnnotatedAttribute(); - PictogramElement ownerAttributeTextShape = getFeatureProvider().getPictogramElementForBusinessObject(ownerAttribute); - IDeleteContext deleteOwnerAttributeContext = new DeleteContext(ownerAttributeTextShape); - feat.delete(deleteOwnerAttributeContext, false); - - JavaPersistentAttribute inverseAttribute = relation.getInverseAnnotatedAttribute(); - PictogramElement inverseAttributeTextShape = getFeatureProvider().getPictogramElementForBusinessObject(inverseAttribute); - IDeleteContext deleteInverseAttributeContext = new DeleteContext(inverseAttributeTextShape); - feat.delete(deleteInverseAttributeContext, false); - } - - postDelete(context); - - /* - IRemoveContext rc = new RemoveContext(pe); - IFeatureProvider featureProvider = getFeatureProvider(); - IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc); - if (removeFeature != null) { - removeFeature.remove(rc); - } - */ - - - } - - public void postDelete(IDeleteContext context) { - PictogramElement pe = context.getPictogramElement(); - Object businessObjectForPictogramElement = getBusinessObjectForPictogramElement(pe); - IRelation rel = (IRelation)businessObjectForPictogramElement; - IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite(); - ICompilationUnit cu = getFeatureProvider().getCompilationUnit(rel.getOwner()); - ut.organizeImports(cu, ws); - if (rel instanceof BidirectionalRelation) { - cu = getFeatureProvider().getCompilationUnit(rel.getInverse()); - ut.organizeImports(cu, ws); - } - } - - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - protected boolean getUserDecision(IDeleteContext context) { - return MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), - JPAEditorMessages.DeleteFeature_deleteConfirm, JPAEditorMessages.DeleteRelationFeature_deleteRelationQuestion); - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java deleted file mode 100644 index bd0b3850a5..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditAttributeFeature.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Kiril Mitov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.text.MessageFormat; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IDirectEditingContext; -import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jdt.core.JavaConventions; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class DirectEditAttributeFeature extends AbstractDirectEditingFeature { - - private boolean isMethodAnnotated = false; - - public DirectEditAttributeFeature(IFeatureProvider fp) { - super(fp); - } - - public int getEditingType() { - return TYPE_TEXT; - } - - @Override - public boolean canDirectEdit(IDirectEditingContext context) { - return true; - } - - public String getInitialValue(IDirectEditingContext context) { - PictogramElement pe = context.getPictogramElement(); - JavaPersistentAttribute jpa = (JavaPersistentAttribute)getFeatureProvider(). - getBusinessObjectForPictogramElement(pe); - isMethodAnnotated = JpaArtifactFactory.instance().isMethodAnnotated(jpa); - Text txt = (Text) pe.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); - String value = txt.getValue(); - if (isMethodAnnotated) - value = JPAEditorUtil.produceValidAttributeName(value); - return value; - } - - @Override - public String checkValueValid(String value, IDirectEditingContext context) { - if (isMethodAnnotated) - value = JPAEditorUtil.produceValidAttributeName(value); - IStatus status = JavaConventions.validateFieldName(value, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5); - if (!status.isOK()) - return status.getMessage(); - status = checkDuplicateAttribute(value, context); - if (!status.isOK()) - return status.getMessage(); - return null; - } - - private IStatus checkDuplicateAttribute(String value, IDirectEditingContext context) { - PictogramElement pe = context.getPictogramElement(); - JavaPersistentAttribute oldAt = (JavaPersistentAttribute) getBusinessObjectForPictogramElement(pe); - JavaPersistentAttribute newAl = (JavaPersistentAttribute)((JavaPersistentType)oldAt.getParent()).getAttributeNamed(value); - if (newAl != null && !newAl.equals(oldAt)) { - String message = MessageFormat.format(JPAEditorMessages.DirectEditAttributeFeature_attributeExists, value); - return new Status(IStatus.ERROR, JPADiagramEditorPlugin.PLUGIN_ID, message); - } - return Status.OK_STATUS; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - public void setValue(String value, IDirectEditingContext context) { - if (isMethodAnnotated) - value = JPAEditorUtil.produceValidAttributeName(value); - PictogramElement pe = context.getPictogramElement(); - JavaPersistentAttribute oldAt = (JavaPersistentAttribute) getBusinessObjectForPictogramElement(pe); - - IRelation rel = getFeatureProvider().getRelationRelatedToAttribute(oldAt); - String inverseJPTName = null; - if (BidirectionalRelation.class.isInstance(rel)) - inverseJPTName = rel.getInverse().getName(); - if (oldAt.getName().equals(value)) - return; - try { - JpaArtifactFactory.instance().renameAttribute(oldAt, value, inverseJPTName, getFeatureProvider()); - } catch (InterruptedException e) { - return; - } - - if (pe.getGraphicsAlgorithm() == null) - return; - final GraphicsAlgorithm alg = pe.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); - final String newValue = value; - - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(alg); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - ((Text) alg).setValue(newValue); - } - }); - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java deleted file mode 100644 index cd6e455357..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DirectEditJPAEntityFeature.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.text.MessageFormat; -import java.util.Iterator; -import java.util.Properties; -import java.util.Set; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IDirectEditingContext; -import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; -import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - - -public class DirectEditJPAEntityFeature extends AbstractDirectEditingFeature { - - private static String allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"; //$NON-NLS-1$ - - public DirectEditJPAEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public int getEditingType() { - return TYPE_TEXT; - } - - @Override - public boolean canDirectEdit(IDirectEditingContext context) { - return true; - } - - public String getInitialValue(IDirectEditingContext context) { - Shape sh = (Shape)context.getPictogramElement(); - ContainerShape csh = sh.getContainer(); - JavaPersistentType jpt = (JavaPersistentType)getBusinessObjectForPictogramElement(csh); - return JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(jpt)); - } - - @Override - public String checkValueValid(String value, IDirectEditingContext context) { - //CSN #1305664 2010 - PictogramElement pe = context.getPictogramElement(); - ContainerShape csh = ((Shape)pe).getContainer(); - JavaPersistentType jpt = (JavaPersistentType) getFeatureProvider().getBusinessObjectForPictogramElement(csh); - String packageName = Signature.getQualifier(jpt.getName()); - PersistenceUnit unit = jpt.getPersistenceUnit(); - - for(ClassRef classRef : unit.getClassRefs()) { - if(classRef.getClassName().equals(packageName + Signature.C_DOT + value) && !(JPAEditorUtil.getText(jpt).equals(value))){ - return MessageFormat.format(JPAEditorMessages.DirectEditJPAEntityFeature_duplicateEntityName, packageName+value); - - } - } - - if (value.length() < 1) - return JPAEditorMessages.DirectEditJPAEntityFeature_classNameMsg; - if (value.contains(" ")) //$NON-NLS-1$ - return JPAEditorMessages.DirectEditJPAEntityFeature_scpacesNotAllowedMsg; - if (value.contains("\n")) //$NON-NLS-1$ - return JPAEditorMessages.DirectEditJPAEntityFeature_lineBreaksNotAllowedMsg; - if(value.contains("{") || value.contains("}")) //$NON-NLS-1$ //$NON-NLS-2$ - return JPAEditorMessages.DirectEditJPAEntityFeature_bracesNotAllowedMsg; - for (int i = 0; i < value.length(); i++) { - if (allowed.indexOf(value.charAt(i)) < 0) - return MessageFormat.format(JPAEditorMessages.DirectEditJPAEntityFeature_invalidSymbolsMsg, value); - } - return null; - } - - @Override - public void setValue(final String value, IDirectEditingContext context) { - PictogramElement pe = context.getPictogramElement(); - ContainerShape csh = ((Shape)pe).getContainer(); - JavaPersistentType jpt = (JavaPersistentType)getBusinessObjectForPictogramElement(csh); - Properties props = JPADiagramPropertyPage.loadProperties(jpt.getJpaProject().getProject()); - - String specifiedEntityMappingName = JpaArtifactFactory.instance().getSpecifiedEntityName(jpt); - if(specifiedEntityMappingName == null){ - RenameEntityWithoutUIFeature ft = new RenameEntityWithoutUIFeature(getFeatureProvider(), value); - ft.execute(jpt); - return; - } else { - - JpaArtifactFactory.instance().renameEntity(jpt, value); -// Properties props = JPADiagramPropertyPage.loadProperties(jpt.getJpaProject().getProject()); - if (JPADiagramPropertyPage.doesDirecteEditingAffectClassNameByDefault(jpt.getJpaProject().getProject(), props)) { - RenameEntityWithoutUIFeature ft = new RenameEntityWithoutUIFeature(getFeatureProvider(), value); - ft.execute(jpt); - return; - } - } - - final GraphicsAlgorithm alg = pe.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); - - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(alg); - ted.getCommandStack().execute(new RecordingCommand(ted) { - @Override - protected void doExecute() { - ((Text) alg).setValue(value); - } - }); - - Set<JavaPersistentAttribute> ats = JpaArtifactFactory.instance().getRelatedAttributes(jpt); - Iterator<JavaPersistentAttribute> it = ats.iterator(); - while (it.hasNext()) { - JavaPersistentAttribute at = it.next(); - PictogramElement pel = getFeatureProvider().getPictogramElementForBusinessObject(at); - String newAtName = JPAEditorUtil.decapitalizeFirstLetter(value); - if (JpaArtifactFactory.instance().isMethodAnnotated(at)) - newAtName = JPAEditorUtil.produceValidAttributeName(newAtName); - try { - newAtName = JpaArtifactFactory.instance().renameAttribute(at, newAtName, jpt.getName(), getFeatureProvider()).getName(); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError(e); - } - - final GraphicsAlgorithm algo = pel.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); - final String attName = newAtName; - TransactionalEditingDomain tedit = TransactionUtil.getEditingDomain(algo); - tedit.getCommandStack().execute(new RecordingCommand(tedit) { - @Override - protected void doExecute() { - ((Text) algo).setValue(attName); - } - }); - } - } - - @Override - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DiscardAndRemoveAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DiscardAndRemoveAllEntitiesFeature.java deleted file mode 100644 index 90b7b10085..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/DiscardAndRemoveAllEntitiesFeature.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Iterator; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.CustomContext; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.swt.widgets.Display; - - -public class DiscardAndRemoveAllEntitiesFeature extends RemoveAllEntitiesFeature { - - public DiscardAndRemoveAllEntitiesFeature(IFeatureProvider fp) { - super(fp); - } - - public String getConfirmationText() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAndDiscardAllEntitiesConfirmation; - } - - public void execute(ICustomContext context) { - MessageDialog dlg = new MessageDialog(Display.getCurrent().getShells()[0], - JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu, - null, getConfirmationText(), 0, - new String[] {JPAEditorMessages.BTN_OK, JPAEditorMessages.BTN_CANCEL}, Dialog.CANCEL); - if (dlg.open() != Dialog.OK) - return; - Iterator<Shape> it = this.getDiagram().getChildren().iterator(); - while (it.hasNext()) { - Shape sh = it.next(); - RestoreEntityFeature ft = new RestoreEntityFeature(getFeatureProvider()); - ICustomContext ctx = new CustomContext(new PictogramElement[] { sh }); - ft.execute(ctx); - allShapes.add(sh); - } - super.execute(context); - } - - @Override - public String getName() { - return JPAEditorMessages.DiscardAndRemoveAllEntitiesFeature_ContextMenuOperationDescription; - - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandAllEntitiesFeature.java deleted file mode 100644 index b801b68e6c..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandAllEntitiesFeature.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class ExpandAllEntitiesFeature extends AbstractCustomFeature{ - - public ExpandAllEntitiesFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - final Diagram diagram = getFeatureProvider().getDiagramTypeProvider().getDiagram(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram); - - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - EList<Shape> shapes = diagram.getChildren(); - for (PictogramElement el : shapes) { - String collapseFeatures = Graphiti.getPeService().getPropertyValue(el, JPAEditorConstants.COLLAPSE_FEATURES); - if (collapseFeatures != null) { - Object bo = getBusinessObjectForPictogramElement(el); - if(bo instanceof JavaPersistentType){ - ContainerShape containerShape = (ContainerShape) el; - GraphicsUpdater.updateEntityShape(containerShape); - GraphicsUpdater.updateEntityHeigth(containerShape); - Graphiti.getPeService().removeProperty(el, JPAEditorConstants.COLLAPSE_FEATURES); - JPAEditorUtil.rearrangeAllConnections(containerShape, getFeatureProvider(), false); - } - } - } - } - }); - - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - @Override - public boolean isAvailable(IContext context) { - return true; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem; - } - - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandCompartmentShapeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandCompartmentShapeFeature.java deleted file mode 100644 index e27e43029a..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandCompartmentShapeFeature.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Petya Sabeva - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.CustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.features.custom.ICustomFeature; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class ExpandCompartmentShapeFeature extends AbstractCustomFeature{ - - public ExpandCompartmentShapeFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - PictogramElement el = context.getPictogramElements()[0]; - - Object ob = getFeatureProvider().getBusinessObjectForPictogramElement(el); - int pictogramHeight = JPAEditorConstants.COMPARTMENT_MIN_HEIGHT; - int newHeight = JPAEditorConstants.COMPARTMENT_BUTTOM_OFFSET; - final ContainerShape containerShape = (ContainerShape) el; - if(ob == null) - newHeight = GraphicsUpdater.increaseCompartmentHeigth(containerShape, newHeight); - final int pictHeight = pictogramHeight + newHeight; - final GraphicsAlgorithm algo = el.getGraphicsAlgorithm(); - final ContainerShape entityShape = containerShape.getContainer(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(algo); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - algo.setHeight(pictHeight); - int height = GraphicsUpdater.getPrimaryShape(entityShape).getGraphicsAlgorithm().getHeight() + - GraphicsUpdater.getRelationShape(entityShape).getGraphicsAlgorithm().getHeight() + - GraphicsUpdater.getBasicShape(entityShape).getGraphicsAlgorithm().getHeight() + JPAEditorConstants.ENTITY_MIN_HEIGHT; - - if(height>entityShape.getGraphicsAlgorithm().getHeight()){ - ICustomContext cont = new CustomContext(new PictogramElement[] {entityShape}); - ICustomFeature expandEntity = new ExpandEntityFeature(getFeatureProvider()); - expandEntity.execute(cont); - } - GraphicsUpdater.updateEntityShape(entityShape); - GraphicsUpdater.setCollapsed(containerShape, false); - JPAEditorUtil.rearrangeAllConnections(entityShape, getFeatureProvider(), false); - } - }); - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - - @Override - public boolean isAvailable(IContext context) { - boolean ret = false; - if (context instanceof ICustomContext) { - PictogramElement[] pes = ((ICustomContext) context).getPictogramElements(); - if (pes != null && pes.length > 0) { - boolean expandPossible = false; - for (int i = 0; i < pes.length; i++) { - PictogramElement pe = pes[i]; - Object bo = getBusinessObjectForPictogramElement(pe); - if (bo != null) { - expandPossible = false; - return false; - } - if (!expandPossible) { - if (GraphicsUpdater.isCollapsed((ContainerShape)pe)) { - expandPossible = true; - } - } - } - if (expandPossible) { - return true; - } - } - } - - return ret; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandEntityFeature.java deleted file mode 100644 index 8c52d27ee6..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ExpandEntityFeature.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Petya Sabeva - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.Property; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class ExpandEntityFeature extends AbstractCustomFeature{ - - public ExpandEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - final PictogramElement el = context.getPictogramElements()[0]; - - Object bo = getBusinessObjectForPictogramElement(el); - if(bo instanceof JavaPersistentType){ - final ContainerShape containerShape = (ContainerShape) el; - - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(containerShape); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - - GraphicsUpdater.updateEntityShape(containerShape); - GraphicsUpdater.updateEntityHeigth(containerShape); - Graphiti.getPeService().removeProperty(el, JPAEditorConstants.COLLAPSE_FEATURES); - - JPAEditorUtil.rearrangeAllConnections(containerShape, getFeatureProvider(), false); - } - }); - } - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - @Override - public boolean isAvailable(IContext context) { - boolean ret = false; - if (context instanceof ICustomContext) { - PictogramElement[] pes = ((ICustomContext) context).getPictogramElements(); - if (pes != null && pes.length > 0) { - boolean expandPossible = false; - for (int i = 0; i < pes.length; i++) { - PictogramElement pe = pes[i]; - Object bo = getBusinessObjectForPictogramElement(pe); - if (!(bo instanceof JavaPersistentType)) { - return false; - } - if (!expandPossible) { - Property property = Graphiti.getPeService().getProperty(pe, JPAEditorConstants.COLLAPSE_FEATURES); - if (property != null) { - expandPossible = true; - } - } - } - if (expandPossible) { - return true; - } - } - } - - return ret; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_expandEntityMenuItem; - } - - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java deleted file mode 100644 index 755d3e88ff..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalAddAttributeFeature.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.HashSet; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IAddContext; -import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; -import org.eclipse.graphiti.mm.algorithms.Image; -import org.eclipse.graphiti.mm.algorithms.Rectangle; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorImageProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.Wrp; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType; - - -public class GraphicalAddAttributeFeature extends AbstractAddShapeFeature { - - public GraphicalAddAttributeFeature(IFeatureProvider fp) { - super(fp); - } - - public PictogramElement add(final IAddContext context) { - final ContainerShape entityShape = context.getTargetContainer(); - final Wrp wrp = new Wrp(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(entityShape); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - JavaPersistentAttribute newAttr = (JavaPersistentAttribute) context.getNewObject(); - String txt = JPAEditorUtil.getText(newAttr); - HashSet<String> annots = JpaArtifactFactory.instance().getAnnotationNames(newAttr); - ContainerShape textShape = null; - ContainerShape primaryShape = GraphicsUpdater.getPrimaryShape(entityShape); - ContainerShape relationShape = GraphicsUpdater.getRelationShape(entityShape); - ContainerShape basicShape = GraphicsUpdater.getBasicShape(entityShape); - textShape = addAttributeToProperlyShape(entityShape, txt, annots, primaryShape, relationShape, basicShape); - link(textShape, newAttr); - layoutPictogramElement(entityShape); - wrp.setObj(textShape); - } - - }); - return (PictogramElement)wrp.getObj(); - } - - private ContainerShape addAttributeToProperlyShape(ContainerShape entityShape, String txt, HashSet<String> annots, - ContainerShape primaryShape, ContainerShape relationShape, ContainerShape basicShape) { - ContainerShape textShape = null; - if (annots.contains(JPAEditorConstants.ANNOTATION_ID) || annots.contains(JPAEditorConstants.ANNOTATION_EMBEDDED_ID)) { - textShape = addAttributeToShape(entityShape, txt, annots, primaryShape); - } else if (annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_MANY) - || annots.contains(JPAEditorConstants.ANNOTATION_MANY_TO_ONE) - || annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_MANY) - || annots.contains(JPAEditorConstants.ANNOTATION_ONE_TO_ONE)) { - textShape = addAttributeToShape(entityShape, txt, annots, relationShape); - } else { - textShape = addAttributeToShape(entityShape, txt, annots, basicShape); - } - return textShape; - } - - private ContainerShape addAttributeToShape(ContainerShape entityShape, String txt, HashSet<String> annots, - ContainerShape containerShape) { - ContainerShape textShape = null; - int childrenSizeBefore = containerShape.getChildren().size(); - int containerHeightBefore = containerShape.getGraphicsAlgorithm().getHeight(); - textShape = addAttribute(getFeatureProvider(), containerShape, txt, annots); - - GraphicsUpdater.updateContainer(containerShape, childrenSizeBefore, containerHeightBefore); - GraphicsUpdater.updateEntityShape(entityShape); - - return textShape; - } - - private static ContainerShape addAttribute(IJPAEditorFeatureProvider fp, ContainerShape containerShape, - String attribTxt, HashSet<String> annotations) { - - int width = containerShape.getContainer().getGraphicsAlgorithm().getWidth(); - ContainerShape iconShape = Graphiti.getPeService().createContainerShape(containerShape, false); - Graphiti.getPeService().setPropertyValue(iconShape, JPAEditorConstants.PROP_SHAPE_TYPE, ShapeType.ICON.toString()); - int attribIndex = fp.getAttribsNum(containerShape); - Rectangle iconRect = UpdateAttributeFeature.addRectangleForIcon(iconShape, attribIndex); - Image icon = null; - Object ob = fp.getBusinessObjectForPictogramElement(containerShape.getContainer()); - JavaPersistentType jpt = (JavaPersistentType)ob; - boolean isMethodAnnotated = JpaArtifactFactory.instance().isMethodAnnotated(jpt); - boolean isCollection = isMethodAnnotated ? - JpaArtifactFactory.instance().isGetterMethodReturnTypeCollection(containerShape.getContainer(), fp, attribTxt) : - JpaArtifactFactory.instance().isCollection(containerShape.getContainer(), fp, attribTxt); - if (isCollection && annotations.isEmpty()) { - icon = Graphiti.getGaService().createImage(iconRect, JPAEditorImageProvider.ICON_UNMAPPED); - } else{ - icon = JPAEditorUtil.createAttributeIcon(iconRect, annotations); - } - Graphiti.getGaService().setLocationAndSize(icon, JPAEditorConstants.ICON_X, JPAEditorConstants.ICON_Y, - JPAEditorConstants.ICON_WIDTH, JPAEditorConstants.ICON_HEIGHT); - ContainerShape textShape = Graphiti.getPeService().createContainerShape(containerShape, false); - Graphiti.getPeService().setPropertyValue(textShape, JPAEditorConstants.PROP_SHAPE_TYPE, ShapeType.ATTRIBUTE.toString()); - Rectangle textRectangle = UpdateAttributeFeature.addRectangleForText(textShape, attribIndex, width); - textShape.setActive(true); - Text text = UpdateAttributeFeature.addText(fp, textRectangle, attribTxt); - Graphiti.getGaService().setWidth(text, width - JPAEditorConstants.ATTRIBUTE_TEXT_RECT_WIDTH_REDUCER); - Graphiti.getGaService().setLocationAndSize(text, 1, -2, width - - JPAEditorConstants.ATTRIBUTE_TEXT_RECT_WIDTH_REDUCER, JPAEditorConstants.ATTRIBUTE_RECT_HEIGHT); - fp.increaseAttribsNum(containerShape); - return textShape; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - public boolean canAdd(IAddContext context) { - return false; - } -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java deleted file mode 100644 index c8d8cdffb8..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/GraphicalRemoveAttributeFeature.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.AddConnectionContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.pictograms.AnchorContainer; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.GraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -class GraphicalRemoveAttributeFeature extends AbstractCustomFeature { - - public GraphicalRemoveAttributeFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - final PictogramElement pe = context.getInnerPictogramElement(); - if (pe == null) - return; - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe); - if (ted == null) - return; - ted.getCommandStack().execute(new RecordingCommand(ted) { - @Override - protected void doExecute() { - Shape sh = (Shape) pe; - Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(sh); - if ((bo == null) || (!JavaPersistentType.class.isInstance(bo))) - return; - ContainerShape entityShape = (ContainerShape) pe; - ContainerShape primShape = GraphicsUpdater.getPrimaryShape(entityShape); - ContainerShape relationShape = GraphicsUpdater.getRelationShape(entityShape); - ContainerShape basicShape = GraphicsUpdater.getBasicShape(entityShape); - - removeCompartmentChildren(primShape); - removeCompartmentChildren(relationShape); - removeCompartmentChildren(basicShape); - - readdCompartmentsChildren((JavaPersistentType) bo, entityShape, primShape, relationShape, basicShape); - - layoutPictogramElement(entityShape); - reconnect((JavaPersistentType) bo); - } - }); - - } - - public void reconnect(JavaPersistentType jpt) { - IJPAEditorFeatureProvider fp = getFeatureProvider(); - Collection<IRelation> rels = JpaArtifactFactory.instance().produceAllRelations(jpt, fp); - JpaArtifactFactory.instance().refreshEntityModel(fp, jpt); - Iterator<IRelation> it = rels.iterator(); - while (it.hasNext()) { - IRelation rel = it.next(); - AddRelationFeature relF = new AddRelationFeature(fp); - AnchorContainer acSource = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getOwner()); - AnchorContainer acTarget = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getInverse()); - AddConnectionContext ctx = new AddConnectionContext(acSource.getAnchors().iterator().next(), acTarget - .getAnchors().iterator().next()); - ctx.setNewObject(rel); - relF.add(ctx); -// JpaArtifactFactory.instance().refreshEntityModel(fp, jpt); - } - } - - @SuppressWarnings("deprecation") - private void readdCompartmentsChildren(JavaPersistentType javaPersistentType, ContainerShape entityShape, - ContainerShape primaryShape, ContainerShape relationShape, ContainerShape basicShape) { - - UpdateAttributeFeature updateFeature = new UpdateAttributeFeature(getFeatureProvider()); - updateFeature.addSeparatorsToShape(primaryShape); - updateFeature.addSeparatorsToShape(relationShape); - updateFeature.addSeparatorsToShape(basicShape); - - for (JavaPersistentAttribute attribute : javaPersistentType.getAttributes()) { - updateFeature.addAttributes(entityShape, attribute); - - getFeatureProvider().renewAttributeJoiningStrategyPropertyListener(attribute); - getFeatureProvider().addJPTForUpdate(javaPersistentType.getName()); - } - } - - private void removeCompartmentChildren(ContainerShape compartmentShape) { - int y = 0; - List<Shape> children = compartmentShape.getChildren(); - for (int i = 0; i < new ArrayList<Shape>(compartmentShape.getChildren()).size(); i++) { - Shape shape = compartmentShape.getChildren().get(i); - y = shape.getGraphicsAlgorithm().getY(); - Graphiti.getPeService().deletePictogramElement(shape); - } - for (int i = getFeatureProvider().getAttribsNum(compartmentShape); i > 0; i--) { - Shape shape = compartmentShape.getChildren().get(i); - y = shape.getGraphicsAlgorithm().getY(); - Graphiti.getPeService().deletePictogramElement(shape); - getFeatureProvider().decreaseAttribsNum(compartmentShape); - } - children = compartmentShape.getChildren(); - shiftUpLowerAttribs(y, children); - compartmentShape.getGraphicsAlgorithm().setHeight(0); - } - - @Override - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - private void shiftUpLowerAttribs(int y, List<Shape> children) { - for (int i = 0; i < children.size(); i++) { - Shape shp = children.get(i); - if (shp != null) { - int grY = children.get(i).getGraphicsAlgorithm().getY(); - if (grY > y) { - children.get(i).getGraphicsAlgorithm().setY(grY - JPAEditorConstants.ATTRIBUTES_PLACEMENT_STEP); - } - children.get(i).setVisible(false); - Graphiti.getPeService().deletePictogramElement(children.get(i)); - } - } - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/JPAMoveConnectionDecoratorFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/JPAMoveConnectionDecoratorFeature.java deleted file mode 100644 index 2180e95041..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/JPAMoveConnectionDecoratorFeature.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IMoveConnectionDecoratorContext; -import org.eclipse.graphiti.features.impl.DefaultMoveConnectionDecoratorFeature; - -public class JPAMoveConnectionDecoratorFeature extends - DefaultMoveConnectionDecoratorFeature { - - public JPAMoveConnectionDecoratorFeature(IFeatureProvider fp) { - super(fp); - } - - @Override - public boolean canExecute(IContext context) { - return false; - } - - @Override - public boolean canMoveConnectionDecorator( - IMoveConnectionDecoratorContext context) { - return false; - } - - @Override - public boolean isAvailable(IContext context) { - return false; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/LayoutJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/LayoutJPAEntityFeature.java deleted file mode 100644 index b9eae4f056..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/LayoutJPAEntityFeature.java +++ /dev/null @@ -1,227 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.graphiti.datatypes.IDimension; -import org.eclipse.graphiti.features.context.ILayoutContext; -import org.eclipse.graphiti.features.impl.AbstractLayoutFeature; -import org.eclipse.graphiti.mm.Property; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.algorithms.Image; -import org.eclipse.graphiti.mm.algorithms.Polyline; -import org.eclipse.graphiti.mm.algorithms.Rectangle; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.algorithms.styles.Point; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IGraphicsUpdater; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; - - -public class LayoutJPAEntityFeature extends AbstractLayoutFeature { - - private IPeServiceUtil peUtil = null; - - public LayoutJPAEntityFeature(IJPAEditorFeatureProvider fp) { - super(fp); - peUtil = fp.getPeUtil(); - } - - public boolean canLayout(ILayoutContext context) { - PictogramElement pe = context.getPictogramElement(); - Object bo = getBusinessObjectForPictogramElement(pe); - return (bo instanceof JavaPersistentType); - } - - public boolean layout(ILayoutContext context) { - boolean anythingChanged = false; - ContainerShape containerShape = (ContainerShape) context - .getPictogramElement(); - GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm(); - - if(containerGa.getHeight() < JPAEditorConstants.ENTITY_MIN_HEIGHT){ - containerGa.setHeight(JPAEditorConstants.ENTITY_MIN_HEIGHT); - } - - configureEntityCollapseExpandProperty(containerShape, containerGa); - - if (containerGa.getWidth() < JPAEditorConstants.ENTITY_MIN_WIDTH) { - containerGa.setWidth(JPAEditorConstants.ENTITY_MIN_WIDTH); - anythingChanged = true; - } - int containerWidth = containerGa.getWidth(); - Iterator<Shape> iter = containerShape.getChildren().iterator(); - while (iter.hasNext()) { - Shape shape = iter.next(); - anythingChanged = layoutContainerEntityChildren(anythingChanged, - containerWidth, shape); - - } - Property property = peUtil.getProperty(containerShape, JPAEditorConstants.COLLAPSE_FEATURES); - if (property == null) { - IGraphicsUpdater gu = getFeatureProvider().getGraphicsUpdater(); - gu.updateEntityHeigth(containerShape); - } - - return anythingChanged; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - private void configureEntityCollapseExpandProperty( - ContainerShape containerShape, GraphicsAlgorithm containerGa) { - if(containerGa.getHeight() == JPAEditorConstants.ENTITY_MIN_HEIGHT){ - peUtil.setPropertyValue(containerShape, JPAEditorConstants.COLLAPSE_FEATURES, String.valueOf(JPAEditorConstants.ENTITY_MIN_HEIGHT)); - } - else if(containerGa.getHeight()>JPAEditorConstants.ENTITY_MIN_HEIGHT){ - peUtil.removeProperty(containerShape, JPAEditorConstants.COLLAPSE_FEATURES); - } - } - - private boolean layoutContainerEntityChildren(boolean anythingChanged, - int containerWidth, Shape shape) { - GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm(); - IDimension size = Graphiti.getGaService().calculateSize(graphicsAlgorithm); - if (containerWidth != size.getWidth()) { - if (graphicsAlgorithm instanceof Polyline) { - anythingChanged = layoutPolyline(containerWidth, - graphicsAlgorithm); - } else if (graphicsAlgorithm instanceof Rectangle) { - - Rectangle rect = (Rectangle) graphicsAlgorithm; - List<GraphicsAlgorithm> gra = rect.getGraphicsAlgorithmChildren(); - Iterator<GraphicsAlgorithm> it = gra.iterator(); - while (it.hasNext()) { - GraphicsAlgorithm gr = it.next(); - if (gr instanceof Image){ - layoutHeaderIcon(shape, graphicsAlgorithm); - } - else if (gr instanceof Text) { - Text txt = (Text) gr; - if(!txt.getFont().isItalic()){ - layoutHeaderText(containerWidth, graphicsAlgorithm, gr); - }else{ - layoutAttributesGroups(anythingChanged, gr, containerWidth); - } - } - } - anythingChanged = true; - } - } - return anythingChanged; - } - - private void layoutHeaderText(int containerWidth, - GraphicsAlgorithm graphicsAlgorithm, GraphicsAlgorithm gr) { - Graphiti.getGaService().setWidth(graphicsAlgorithm, - containerWidth - JPAEditorConstants.HEADER_TEXT_RECT_WIDTH_REDUCER); - Graphiti.getGaService().setWidth(gr, containerWidth - JPAEditorConstants.HEADER_TEXT_RECT_WIDTH_REDUCER); - } - - private void layoutHeaderIcon(Shape shape, - GraphicsAlgorithm graphicsAlgorithm) { - GraphicsAlgorithm headerIconGraphicsAlg = shape - .getGraphicsAlgorithm(); - Graphiti.getGaService().setWidth(graphicsAlgorithm, JPAEditorConstants.HEADER_ICON_RECT_WIDTH); - Graphiti.getGaService().setWidth(headerIconGraphicsAlg, JPAEditorConstants.HEADER_ICON_RECT_HEIGHT); - } - - private boolean layoutPolyline(int containerWidth, - GraphicsAlgorithm graphicsAlgorithm) { - boolean anythingChanged; - Polyline headerBottomLine = (Polyline) graphicsAlgorithm; - Point secondPoint = headerBottomLine.getPoints().get(1); - Point newSecondPoint = Graphiti.getGaService().createPoint(/* headerBottomLine, */ - containerWidth, secondPoint.getY()); - headerBottomLine.getPoints().set(1, newSecondPoint); - anythingChanged = true; - return anythingChanged; - } - - private void layoutAttributesGroups(boolean anythingChanged, GraphicsAlgorithm graphicsAlgorithm, - int containerWidth) { - ContainerShape containerShape = (ContainerShape) Graphiti.getPeService().getActiveContainerPe(graphicsAlgorithm); - layoutConcreteCompartmentShape(anythingChanged, containerShape, containerWidth); - } - - private void layoutConcreteCompartmentShape(boolean anythingChanged, ContainerShape containerShape, - int containerWidth) { - - layoutCompartmentShape(containerShape, containerWidth); - - Iterator<Shape> iter = containerShape.getChildren().iterator(); - while(iter.hasNext()) { - Shape shape = iter.next(); - GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm(); - if (graphicsAlgorithm instanceof Rectangle) { - Rectangle rect = (Rectangle) graphicsAlgorithm; - List<GraphicsAlgorithm> gra = rect.getGraphicsAlgorithmChildren(); - if(gra.isEmpty()){ - Graphiti.getGaService().setWidth(graphicsAlgorithm, containerWidth); - } - Iterator<GraphicsAlgorithm> it = gra.iterator(); - while (it.hasNext()) { - GraphicsAlgorithm gr = it.next(); - if (gr instanceof Image) { - layoutAttributeIcon(shape, graphicsAlgorithm); - } - if (gr instanceof Text) { - layoutAttributeText(containerWidth, graphicsAlgorithm, gr); - } - } - anythingChanged = true; - } - } - } - - private void layoutAttributeText(int containerWidth, - GraphicsAlgorithm graphicsAlgorithm, GraphicsAlgorithm gr) { - Graphiti.getGaService().setWidth(graphicsAlgorithm, - containerWidth - JPAEditorConstants.ATTRIBUTE_TEXT_RECT_WIDTH_REDUCER); - Graphiti.getGaService().setWidth(gr, - containerWidth - JPAEditorConstants.ATTRIBUTE_TEXT_RECT_WIDTH_REDUCER); - } - - private void layoutAttributeIcon(Shape shape, - GraphicsAlgorithm graphicsAlgorithm) { - GraphicsAlgorithm headerIconGraphicsAlg = shape.getGraphicsAlgorithm(); - Graphiti.getGaService().setWidth(graphicsAlgorithm,JPAEditorConstants.ICON_RECT_WIDTH); - Graphiti.getGaService().setWidth(headerIconGraphicsAlg, JPAEditorConstants.ICON_RECT_WIDTH); - } - - private void layoutCompartmentShape(ContainerShape containerShape, - int containerWidth) { - GraphicsAlgorithm graphic = containerShape.getGraphicsAlgorithm(); - List<GraphicsAlgorithm> graphics = graphic.getGraphicsAlgorithmChildren(); - Iterator<GraphicsAlgorithm> iterator = graphics.iterator(); - while (iterator.hasNext()) { - GraphicsAlgorithm graphicsAlgorithm = iterator.next(); - Graphiti.getGaService().setWidth(graphic, containerWidth); - Graphiti.getGaService().setWidth(graphicsAlgorithm, containerWidth); - } - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveAttributeFeature.java deleted file mode 100644 index fd9e639f1a..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveAttributeFeature.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IMoveShapeContext; -import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature; - -/* - * The attribute shapes (residing within the entity shapes) - * are NOT supposed to be moveable (at least - not by - * drag-and-drop). The only purpose of this class is to - * disable this ability - * - */ - -public class MoveAttributeFeature extends DefaultMoveShapeFeature { - public MoveAttributeFeature(IFeatureProvider fp) { - super(fp); - } - - public boolean canMoveShape(IMoveShapeContext context) { - return false; - } - - - public boolean canExecute(IContext context) { - return false; - } - - - public boolean isAvailable(IContext context) { - return false; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityFeature.java deleted file mode 100644 index 9fbf3ca1e5..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityFeature.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgMoveAction; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; - -@SuppressWarnings("restriction") -public class MoveEntityFeature extends RefactorEntityFeature { - - public MoveEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt); - IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite(); - ReorgMoveAction action = new ReorgMoveAction(ws); - execute(context, action, cu); - } - - - @Override - public String getName() { - return JPAEditorMessages.MoveEntityFeature_ContextMenuOperationDescription; - } - - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java deleted file mode 100644 index 4d167a7bc4..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/MoveEntityShapeFeature.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IMoveShapeContext; -import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class MoveEntityShapeFeature extends DefaultMoveShapeFeature { - - public MoveEntityShapeFeature(IFeatureProvider fp) { - super(fp); - } - - protected void moveAllBendpoints(IMoveShapeContext context) { - } - - protected void postMoveShape(IMoveShapeContext context) { - ContainerShape cs = (ContainerShape)context.getShape(); - JPAEditorUtil.rearrangeAllConnections(cs, getFeatureProvider(), false); - Collection<ContainerShape> css = JPAEditorUtil.getRelatedShapes(cs); - Iterator<ContainerShape> csIt = css.iterator(); - while (csIt.hasNext()) { - ContainerShape cs1 = csIt.next(); - JPAEditorUtil.rearrangeAllConnections(cs1, getFeatureProvider(), true); - } - } - - @Override - protected void internalMove(final IMoveShapeContext context) { - PictogramElement el = context.getPictogramElement(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(el); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - move(context); - } - }); - } - - public void move(IMoveShapeContext context){ - super.internalMove(context); - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/OpenJPADetailsViewFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/OpenJPADetailsViewFeature.java deleted file mode 100644 index e6f881c9c6..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/OpenJPADetailsViewFeature.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; - - -public class OpenJPADetailsViewFeature extends AbstractCustomFeature { - - public OpenJPADetailsViewFeature(IFeatureProvider fp) { - super(fp); - } - - public boolean canExecute(ICustomContext context) { - return true; - } - - public void execute(ICustomContext context) { - try { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(). - showView(JPAEditorConstants.ID_VIEW_JPA_DETAILS); - } catch (PartInitException e) { - JPADiagramEditorPlugin.logError("Can't open JPA Details view", e); //$NON-NLS-1$ - } - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/OpenMiniatureViewFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/OpenMiniatureViewFeature.java deleted file mode 100644 index bcd7856b51..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/OpenMiniatureViewFeature.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; - - -public class OpenMiniatureViewFeature extends AbstractCustomFeature { - - public OpenMiniatureViewFeature(IFeatureProvider fp) { - super(fp); - } - - public boolean canExecute(ICustomContext context) { - return true; - } - - public void execute(ICustomContext context) { - try { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(). - showView(JPAEditorConstants.ID_VIEW_MINIATURE); - } catch (PartInitException e) { - JPADiagramEditorPlugin.logError("Can't open Miniature view", e); //$NON-NLS-1$ - } - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_openMiniatureView; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java deleted file mode 100644 index c5c4387291..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorAttributeTypeFeature.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.text.MessageFormat; -import java.util.List; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement.Kind; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.dialog.SelectTypeDialog; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; - - -public class RefactorAttributeTypeFeature extends AbstractCustomFeature { - - //private static final TracerI tracer = TracingManager.getTracer(RefactorAttributeTypeFeature.class); - - public RefactorAttributeTypeFeature(IFeatureProvider fp) { - super(fp); - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - - public void execute(ICustomContext context) { - PictogramElement pe = context.getPictogramElements()[0]; - Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe); - if ((bo == null) || (!(bo instanceof JavaPersistentAttribute))) - return; - JavaPersistentAttribute jpa = (JavaPersistentAttribute)bo; - String typeName = JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa); - String msg = MessageFormat.format(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogText, - jpa.getName(), JPAEditorUtil.returnSimpleName(((PersistentType)jpa.getParent()).getName())); - SelectTypeDialog d = new SelectTypeDialog(msg, typeName); - if (d.open() != IDialogConstants.OK_ID) - return; - String newTypeName = d.getTypeName(); - String[] attributeTypeTypeNames = JPAEditorUtil.getGenericsElementTypes(newTypeName); - if (attributeTypeTypeNames != null) - newTypeName = newTypeName.substring(0, newTypeName.indexOf('<')).trim(); - - getFeatureProvider().addAddIgnore((JavaPersistentType)jpa.getParent(), jpa.getName()); - JavaResourceAttribute jra = jpa.getResourceAttribute(); - getFeatureProvider().addRemoveIgnore((JavaPersistentType)jpa.getParent(), jra.getName()); - boolean isMethodAnnotated = jra.getKind() == Kind.METHOD; - - List<String> annotations = JpaArtifactFactory.instance().getAnnotationStrings(jpa); - JpaArtifactFactory.instance().deleteAttribute((JavaPersistentType)jpa.getParent(), jpa.getName(), - getFeatureProvider()); - JavaPersistentAttribute newAt = JpaArtifactFactory.instance().createANewAttribute((JavaPersistentType)jpa.getParent(), - jpa.getName(), newTypeName, attributeTypeTypeNames, jpa.getName(), annotations, - false, isMethodAnnotated, getFeatureProvider()); - getFeatureProvider().replaceAttribute(jpa, newAt); - IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite(); - ICompilationUnit cu = getFeatureProvider().getCompilationUnit((JavaPersistentType)newAt.getParent()); - getFeatureProvider().getJPAEditorUtil().formatCode(cu, ws); - JpaArtifactFactory.instance().remakeRelations(getFeatureProvider(), - ((Shape)pe).getContainer(), (JavaPersistentType)newAt.getParent()); - } - - @Override - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - @Override - public String getName() { - return JPAEditorMessages.RefactorAttributeTypeFeature_ContextMenuOperationDescription; - } - - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java deleted file mode 100644 index ea7ca502ac..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java +++ /dev/null @@ -1,363 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Set; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.IRemoveContext; -import org.eclipse.graphiti.features.context.impl.AddContext; -import org.eclipse.graphiti.features.context.impl.RemoveContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.algorithms.RoundedRectangle; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.ui.actions.SelectionDispatchAction; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jpt.common.core.JptResourceModel; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.common.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.common.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.jpa.core.JpaFile; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.jpa.core.resource.java.OwnableRelationshipMappingAnnotation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.AddEntityContext; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPASolver; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Display; - - -public abstract class RefactorEntityFeature extends AbstractCustomFeature { - - protected JavaPersistentType jpt = null; - protected Set<JavaPersistentAttribute> ats = null; - protected boolean hasNameAnnotation = false; - - public RefactorEntityFeature(IFeatureProvider fp) { - super(fp); - } - - @Override - public boolean isAvailable(IContext context) { - if (!(context instanceof ICustomContext)) - return false; - ICustomContext ctx = (ICustomContext)context; - PictogramElement pe = ctx.getInnerPictogramElement(); - Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe); - if (bo instanceof JavaPersistentType) { - jpt = (JavaPersistentType)bo; - hasNameAnnotation = JpaArtifactFactory.instance().hasNameAnnotation(jpt); - return true; - } - if (pe instanceof Shape) { - ContainerShape cs = ((Shape)pe).getContainer(); - if (cs == null) - return false; - bo = getFeatureProvider().getBusinessObjectForPictogramElement(cs); - if (bo instanceof JavaPersistentType) { - jpt = (JavaPersistentType)bo; - hasNameAnnotation = JpaArtifactFactory.instance().hasNameAnnotation(jpt); - return true; - } - } - return false; - } - - @Override - public boolean canExecute(ICustomContext context) { - return true; - } - - public void execute(ICustomContext context, SelectionDispatchAction action, ICompilationUnit cu) { - StructuredSelection sel = new StructuredSelection(cu); - final Shape pict = (Shape)getFeatureProvider().getPictogramElementForBusinessObject(jpt); - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider(). - getBusinessObjectForPictogramElement(pict); - final PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt); - final Semaphore s = new Semaphore(0); - final JPAProjectListener lsnr = new JPAProjectListener(s); - jpt.getJpaProject().addCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, lsnr); - ShowBusy showBusy = new ShowBusy(s); - JPASolver.ignoreEvents = true; - final String oldName = jpt.getName(); - - try { - action.run(sel); - } catch (Exception e) {} - BusyIndicator.showWhile(Display.getCurrent(), showBusy); - jpt.getJpaProject().removeCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, lsnr); - JPASolver.ignoreEvents = false; - final boolean rename = RenameEntityFeature.class.isInstance(this); - - if (!showBusy.isMoved()) - return; - - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pict); - ted.getCommandStack().execute(new RecordingCommand(ted) { - @Override - protected void doExecute() { - remapEntity(oldName, pict, pu, rename, lsnr, getFeatureProvider()); - } - }); - } - - public void execute(ICustomContext context, String newName, ICompilationUnit cu, JavaPersistentType jpt) { - final String oldName = jpt.getName(); - final Shape pict = (Shape)getFeatureProvider().getPictogramElementForBusinessObject(jpt); - jpt = (JavaPersistentType)getFeatureProvider(). - getBusinessObjectForPictogramElement(pict); - final PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpt); - final Semaphore s = new Semaphore(0); - final JPAProjectListener lsnr = new JPAProjectListener(s); - jpt.getJpaProject().addCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, lsnr); - ShowBusy showBusy = new ShowBusy(s); - JPASolver.ignoreEvents = true; - JpaArtifactFactory.instance().renameEntityClass(jpt, newName, getFeatureProvider()); - BusyIndicator.showWhile(Display.getCurrent(), showBusy); - jpt.getJpaProject().removeCollectionChangeListener(JpaProject.JPA_FILES_COLLECTION, lsnr); - JPASolver.ignoreEvents = false; - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pict); - ted.getCommandStack().execute(new RecordingCommand(ted) { - @Override - protected void doExecute() { - remapEntity(oldName, pict, pu, true, lsnr, getFeatureProvider()); - } - }); - } - - public static void remapEntity(final String oldName, - final Shape pict, - final PersistenceUnit pu, - final boolean rename, - final JPAProjectListener lsnr, - final IJPAEditorFeatureProvider fp) { - BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { - public void run() { - pu.getJpaProject().updateAndWait(); - final int x = pict.getGraphicsAlgorithm().getX(); - final int y = pict.getGraphicsAlgorithm().getY(); - final int width = pict.getGraphicsAlgorithm().getWidth(); - final int height = pict.getGraphicsAlgorithm().getHeight(); - - final ContainerShape cs = Graphiti.getPeService().createContainerShape(fp.getDiagramTypeProvider().getDiagram(), - true); - cs.setVisible(true); - - AddContext cont = new AddContext(); - cont.setX(x); - cont.setY(y); - cont.setWidth(width); - cont.setHeight(height); - RoundedRectangle rect = AddJPAEntityFeature.createEntityRectangle(cont, cs, fp.getDiagramTypeProvider().getDiagram()); - rect.setFilled(true); - - IRemoveContext ctx = new RemoveContext(pict); - RemoveJPAEntityFeature ft = new RemoveJPAEntityFeature(fp); - - boolean primaryCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.PRIMARY_COLLAPSED)); - boolean relationCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.RELATION_COLLAPSED)); - boolean basicCollapsed = JPAEditorConstants.TRUE_STRING.equals(Graphiti.getPeService().getPropertyValue(pict, JPAEditorConstants.BASIC_COLLAPSED)); - - AddEntityContext addCtx = new AddEntityContext(primaryCollapsed, relationCollapsed, basicCollapsed); - String newJPTName = lsnr.getNewJPTName(); - - JavaPersistentType newJPT = JpaArtifactFactory.instance().getJPT(newJPTName, pu); - if (!JptJpaCorePlugin.discoverAnnotatedClasses(newJPT.getJpaProject().getProject())) { - JPAEditorUtil.createUnregisterEntityFromXMLJob(newJPT.getJpaProject(), oldName); - } - if (rename) { - String tableName = JPAEditorUtil.formTableName(newJPT); - JpaArtifactFactory.instance().setTableName(newJPT, tableName); - } - addCtx.setNewObject(newJPT); - addCtx.setTargetContainer(fp.getDiagramTypeProvider().getDiagram()); - addCtx.setX(x); - addCtx.setY(y); - addCtx.setWidth(width); - addCtx.setHeight(height); - AddJPAEntityFeature ft1 = new AddJPAEntityFeature(fp); - ft.remove(ctx); - ft1.add(addCtx); - PictogramElement pe = fp.getPictogramElementForBusinessObject(newJPT); - fp.getDiagramTypeProvider().getDiagramEditor().setPictogramElementForSelection(pe); - Graphiti.getPeService().deletePictogramElement(cs); - - JpaArtifactFactory.instance().refreshEntityModel(fp, newJPT); - if (!JptJpaCorePlugin.discoverAnnotatedClasses(newJPT.getJpaProject().getProject())) { - JPAEditorUtil.createRegisterEntityInXMLJob(newJPT.getJpaProject(), newJPTName); - } - } - }); - - } - - - - @Override - protected Diagram getDiagram() { - return getFeatureProvider().getDiagramTypeProvider().getDiagram(); - } - - @Override - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - class ShowBusy implements Runnable { - private Semaphore s; - boolean moved = false; - ShowBusy(Semaphore s) { - this.s = s; - } - - public void run() { - try { - moved = s.tryAcquire(2, 4, TimeUnit.SECONDS); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError("Thread interrupted", e); //$NON-NLS-1$ - } - } - - boolean isMoved() { - return moved; - } - } - - public class JPAProjectListener implements CollectionChangeListener { - private Semaphore s = null; - private String newJptName = null; - - public JPAProjectListener(Semaphore s) { - this.s = s; - } - - public void itemsAdded(CollectionAddEvent event) { - Iterator<?> it = event.getItems().iterator(); - Object o = it.next(); - JpaFile jpaFile = (JpaFile)o; - - JptResourceModel rm = jpaFile.getResourceModel(); - if (rm == null) - return; - if (!JavaResourceCompilationUnit.class.isInstance(rm)) - return; - JavaResourceCompilationUnit jrcu = (JavaResourceCompilationUnit)rm; - JavaResourceAbstractType jrt = jrcu.getPrimaryType(); - newJptName = jrt.getQualifiedName(); - s.release(); - if ((ats == null) || hasNameAnnotation) - return; - final Iterator<JavaPersistentAttribute> iter = ats.iterator(); - Runnable r = new Runnable() { - public void run() { - Hashtable<String, String> atOldToNewName = new Hashtable<String, String>(); - Set<JavaPersistentAttribute> newSelfAts = new HashSet<JavaPersistentAttribute>(); - while (iter.hasNext()) { - JavaPersistentAttribute at = iter.next(); - ICompilationUnit cu = getFeatureProvider().getCompilationUnit((JavaPersistentType) at.getParent()); - if (!cu.exists()) { - at = (JavaPersistentAttribute)at.getPersistenceUnit().getPersistentType(newJptName).getAttributeNamed(at.getName()); - JavaPersistentAttribute newAt = null; - try { - newAt = JpaArtifactFactory.instance().renameAttribute(at, JPAEditorUtil.returnSimpleName(newJptName), newJptName, getFeatureProvider()); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError(e); - } - atOldToNewName.put(at.getName(), newAt.getName()); - newSelfAts.add(newAt); - } else { - try { - JpaArtifactFactory.instance().renameAttribute(at, JPAEditorUtil.returnSimpleName(newJptName), newJptName, getFeatureProvider()); - } catch (InterruptedException e) { - JPADiagramEditorPlugin.logError(e); - } - } - } - Iterator<JavaPersistentAttribute> itr = newSelfAts.iterator(); - while (itr.hasNext()) { - JavaPersistentAttribute at = itr.next(); - JpaArtifactFactory.instance().refreshEntityModel(null, (JavaPersistentType)at.getParent()); - JavaAttributeMapping m = at.getMapping(); - Annotation mappingAnnotation = m.getMappingAnnotation(); - - if(mappingAnnotation == null){ - JpaArtifactFactory.instance().refreshEntityModel(getFeatureProvider(), (JavaPersistentType)at.getParent()); - mappingAnnotation = m.getMappingAnnotation(); - } - if (mappingAnnotation == null) - return; - if (OwnableRelationshipMappingAnnotation.class.isInstance(mappingAnnotation)) { - OwnableRelationshipMappingAnnotation ownableMappingAnnotation = (OwnableRelationshipMappingAnnotation)mappingAnnotation; - String oldMappedBy = ownableMappingAnnotation.getMappedBy(); - if (oldMappedBy != null) { - String newMappedBy = atOldToNewName.get(oldMappedBy); - if (newMappedBy != null) - ownableMappingAnnotation.setMappedBy(newMappedBy); - } - } - } - - } - }; - Display.getDefault().asyncExec(r); - } - - public void itemsRemoved(CollectionRemoveEvent arg0) { - s.release(); - } - - public void collectionChanged(CollectionChangeEvent event) { - } - - public void collectionCleared(CollectionClearEvent arg0) {} - - public String getNewJPTName() { - return newJptName; - } - - - }; - - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAllEntitiesFeature.java deleted file mode 100644 index f1225ab4c6..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAllEntitiesFeature.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.IRemoveContext; -import org.eclipse.graphiti.features.context.impl.RemoveContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; - -public abstract class RemoveAllEntitiesFeature extends AbstractCustomFeature { - - protected Set<Shape> allShapes = new HashSet<Shape>(); - - public RemoveAllEntitiesFeature(IFeatureProvider fp) { - super(fp); - } - - public abstract String getConfirmationText(); - - public boolean canExecute(ICustomContext context) { - return true; - } - - public void execute(ICustomContext context) { - Iterator<Shape> it = allShapes.iterator(); - while (it.hasNext()) { - Shape sh = it.next(); - final RemoveJPAEntityFeature ft = new RemoveJPAEntityFeature(this.getFeatureProvider()); - final IRemoveContext ctx = new RemoveContext(sh); - PictogramElement pe = ctx.getPictogramElement(); - - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe); - ted.getCommandStack().execute(new RecordingCommand(ted) { - @Override - protected void doExecute() { - ft.remove(ctx); - } - }); - } - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java deleted file mode 100644 index b70aaa5289..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAndSaveEntityFeature.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IRemoveContext; -import org.eclipse.graphiti.features.context.impl.RemoveContext; -import org.eclipse.graphiti.features.impl.DefaultRemoveFeature; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; - - - -public class RemoveAndSaveEntityFeature extends DefaultRemoveFeature { - - public RemoveAndSaveEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public void preRemove(IRemoveContext context) { - PictogramElement pe = context.getPictogramElement(); - Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe); - Set<Shape> shapesForDeletion = new HashSet<Shape>(); - if (bo instanceof PersistentType) { - IFeatureProvider fp = getFeatureProvider(); - List<Shape> lst = ((ContainerShape)pe).getChildren(); - for (int i = lst.size() - 1; i >= 0; i--) { - Shape textShape = lst.get(i); - Object o = fp.getBusinessObjectForPictogramElement(textShape); - if ((o != null) && (o instanceof JavaPersistentAttribute)) { - shapesForDeletion.add(textShape); - } - } - Iterator<Shape> it = shapesForDeletion.iterator(); - while(it.hasNext()) { - RemoveAttributeFeature f = new RemoveAttributeFeature(fp, false, true); - IRemoveContext ctx = new RemoveContext(it.next()); - f.remove(ctx); - } - getFeatureProvider().remove(((PersistentType)bo).getName(), true); - } - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java deleted file mode 100644 index 055d602afb..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveAttributeFeature.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IRemoveContext; -import org.eclipse.graphiti.features.context.impl.AddConnectionContext; -import org.eclipse.graphiti.features.context.impl.CustomContext; -import org.eclipse.graphiti.features.context.impl.RemoveContext; -import org.eclipse.graphiti.features.custom.ICustomFeature; -import org.eclipse.graphiti.features.impl.DefaultRemoveFeature; -import org.eclipse.graphiti.mm.pictograms.Connection; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class RemoveAttributeFeature extends DefaultRemoveFeature { - - private boolean skipRemoveRelations = false; - private boolean skipCreateRelations = false; - private JavaPersistentType jpt = null; - private ICustomFeature graphicalRemove; - - public RemoveAttributeFeature(IFeatureProvider fp) { - this(fp, new GraphicalRemoveAttributeFeature(fp)); - } - - public RemoveAttributeFeature(IFeatureProvider fp, boolean skipRemoveRelations, boolean skipCreateRelations) { - this(fp); - this.skipRemoveRelations = skipRemoveRelations; - this.skipCreateRelations = skipCreateRelations; - } - - public RemoveAttributeFeature(IFeatureProvider fp, ICustomFeature graphicalRemove) { - super(fp); - this.graphicalRemove = graphicalRemove; - } - - public void setKey(String key) { - } - - public boolean isAvailable(IContext context) { - return false; - } - - public boolean canExecute(IContext context) { - return false; - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - public void preRemove(IRemoveContext context) { - final PictogramElement pe = context.getPictogramElement(); - if (pe == null) { - JPADiagramEditorPlugin.logError("PictogramElement is null\n", new Exception()); //$NON-NLS-1$ - return; - } - IJPAEditorFeatureProvider fp = getFeatureProvider(); - Object bo = fp.getBusinessObjectForPictogramElement(pe); - if(bo == null) - return; - - if (bo instanceof JavaPersistentAttribute) { - JavaPersistentAttribute jpa = (JavaPersistentAttribute) bo; - - HashSet<String> ignores = ((JPAEditorFeatureProvider) getFeatureProvider()).getAddIgnore(); - if (!ignores.isEmpty()) { - Iterator<String> iter = ignores.iterator(); - if (iter.hasNext()) { - String iterStr = iter.next(); - if (iterStr.endsWith(jpa.getName())) { - ignores.remove(iterStr); - } - } - } - - jpt = (JavaPersistentType)jpa.getParent(); - fp.remove(fp.getKeyForBusinessObject(bo)); - if (!skipRemoveRelations) { - IRelation rel = fp.getRelationRelatedToAttribute(jpa); - removeRelation(rel); - } - } - - ContainerShape entityShape = ((ContainerShape) pe).getContainer().getContainer(); - try{ - graphicalRemoveAttribute(entityShape); - } catch (Exception e){ - JPADiagramEditorPlugin.logError(e); - } - } - - private void graphicalRemoveAttribute(PictogramElement pe) { - CustomContext customContext = new CustomContext(); - customContext.setInnerPictogramElement(pe); - graphicalRemove.execute(customContext); - } - - private void removeRelation(IRelation rel) { - if (rel == null) - return; - Connection conn = (Connection) getFeatureProvider().getPictogramElementForBusinessObject(rel); - RemoveContext ctx = new RemoveContext(conn); - RemoveRelationFeature ft = new RemoveRelationFeature(getFeatureProvider()); - ft.remove(ctx); - } - - public void postRemove(IRemoveContext context) { - if (skipCreateRelations) - return; - if (jpt == null) - return; - JpaArtifactFactory.instance().refreshEntityModel(getFeatureProvider(), jpt); - - Collection<IRelation> rels = JpaArtifactFactory.instance() - .produceAllRelations(jpt, getFeatureProvider()); - Iterator<IRelation> iter = rels.iterator(); - while (iter.hasNext()) { - IRelation rel = iter.next(); - ContainerShape ownerShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject( - rel.getOwner()); - ContainerShape inverseShape = (ContainerShape) getFeatureProvider().getPictogramElementForBusinessObject( - rel.getInverse()); - AddConnectionContext cntx = new AddConnectionContext(JPAEditorUtil.getAnchor(ownerShape), JPAEditorUtil - .getAnchor(inverseShape)); - cntx.setNewObject(rel); - AddRelationFeature ft = new AddRelationFeature(getFeatureProvider()); - ft.add(cntx); -// JpaArtifactFactory.instance().refreshEntityModel(getFeatureProvider(), jpt); - } - } - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java deleted file mode 100644 index e188f0705e..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveJPAEntityFeature.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IRemoveContext; -import org.eclipse.graphiti.features.context.impl.RemoveContext; -import org.eclipse.graphiti.features.impl.DefaultRemoveFeature; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.ui.PlatformUI; - - -public class RemoveJPAEntityFeature extends DefaultRemoveFeature { - - - public RemoveJPAEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public void preRemove(IRemoveContext context) { - PictogramElement pe = context.getPictogramElement(); - -// RestoreEntityFeature ft = new RestoreEntityFeature(getFeatureProvider()); -// ICustomContext customContext = new CustomContext(new PictogramElement[] { pe }); -// ft.execute(customContext); - - final Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe); - Set<Shape> shapesForDeletion = new HashSet<Shape>(); - if (bo instanceof JavaPersistentType) { - JavaPersistentType jpt = (JavaPersistentType)bo; - JpaArtifactFactory.instance().restoreEntityClass(jpt, getFeatureProvider()); - IFeatureProvider fp = getFeatureProvider(); - List<Shape> lst = ((ContainerShape)pe).getChildren(); - for (int i = lst.size() - 1; i >= 0; i--) { - Shape textShape = lst.get(i); - Object o = fp.getBusinessObjectForPictogramElement(textShape); - if ((o != null) && (o instanceof JavaPersistentAttribute)) { - shapesForDeletion.add(textShape); - } - } - Iterator<Shape> it = shapesForDeletion.iterator(); - while(it.hasNext()) { - RemoveAttributeFeature f = new RemoveAttributeFeature(fp, false, true); - IRemoveContext ctx = new RemoveContext(it.next()); - f.remove(ctx); - } - //--------------------------------------------------------------------- - //--Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=281345 - //Job job = new Job("Remove JPA entity") { //$NON-NLS-1$ - // protected IStatus run(IProgressMonitor monitor) { - String name = ((PersistentType)bo).getName(); - getFeatureProvider().remove(name, true); - //return new Status(IStatus.OK, - // JPADiagramEditorPlugin.PLUGIN_ID, - // name + " is removed"); //$NON-NLS-1$ - - // } - //}; - //job.schedule(); - //--------------------------------------------------------------------- - } - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - - public void execute(IContext ctx) { - if (!IRemoveContext.class.isInstance(ctx)) - return; - IRemoveContext context = (IRemoveContext)ctx; - PictogramElement pe = context.getPictogramElement(); - Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe); - if (!JavaPersistentType.class.isInstance(bo)) - return; - JavaPersistentType jpt = (JavaPersistentType)bo; - if (JPAEditorUtil.isEntityOpenElsewhere(jpt, true)) { - String shortEntName = JPAEditorUtil.returnSimpleName(JpaArtifactFactory.instance().getEntityName(jpt)); - String message = NLS.bind(JPAEditorMessages.RemoveJPAEntityFeature_discardWarningMsg, shortEntName); - MessageDialog dialog = new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), - JPAEditorMessages.JPASolver_closeEditors, null, message, - MessageDialog.WARNING, new String[]{JPAEditorMessages.BTN_OK, JPAEditorMessages.BTN_CANCEL}, 0) { - protected int getShellStyle() { - return SWT.CLOSE - | SWT.TITLE | SWT.BORDER - | SWT.APPLICATION_MODAL - | getDefaultOrientation();}}; - if (dialog.open() != 0) - return; - } - super.execute(context); - } - - - - - - -}
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java deleted file mode 100644 index 6f73e1dc16..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RemoveRelationFeature.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Iterator; - -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.IRemoveFeature; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IRemoveContext; -import org.eclipse.graphiti.features.context.impl.RemoveContext; -import org.eclipse.graphiti.features.impl.AbstractFeature; -import org.eclipse.graphiti.internal.Messages; -import org.eclipse.graphiti.mm.pictograms.Anchor; -import org.eclipse.graphiti.mm.pictograms.Connection; -import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation; - - -@SuppressWarnings("restriction") -public class RemoveRelationFeature extends AbstractFeature implements IRemoveFeature { - - private static final String NAME = Messages.DefaultRemoveFeature_0_xfld; - - public RemoveRelationFeature(IFeatureProvider fp) { - super(fp); - } - - public boolean isAvailable(IContext context) { - return true; - } - - public boolean canRemove(IRemoveContext context) { - return true; - } - - public boolean canExecute(IContext context) { - return true; - } - - public void preRemove(IRemoveContext context) { - PictogramElement pe = context.getPictogramElement(); - Object bo = getFeatureProvider().getBusinessObjectForPictogramElement(pe); - if (bo instanceof AbstractRelation) { - AbstractRelation rel = (AbstractRelation)bo; - getFeatureProvider().remove(rel.getId()); - } - } - - public final void remove(final IRemoveContext context) { - if (!getUserDecision()) { - return; - } - preRemove(context); - final PictogramElement pe = context.getPictogramElement(); - if (pe == null) - return; - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(pe); - RecordingCommand rc = new RecordingCommand(ted) { - protected void doExecute() { - if (pe instanceof Shape) { - Shape shape = (Shape) pe; - removeAllConnections(shape); - } - Graphiti.getPeService().deletePictogramElement(pe); - postRemove(context); - } - }; - ted.getCommandStack().execute(rc); - } - - protected void removeAllConnections(Shape shape) { - IFeatureProvider featureProvider = getFeatureProvider(); - for (Iterator<Anchor> iter = shape.getAnchors().iterator(); iter.hasNext();) { - Anchor anchor = iter.next(); - for (Iterator<Connection> iterator = Graphiti.getPeService().getAllConnections(anchor).iterator(); iterator.hasNext();) { - Connection connection = iterator.next(); - if (connection.eResource() != null) { - IRemoveContext rc = new RemoveContext(connection); - IRemoveFeature removeFeature = featureProvider.getRemoveFeature(rc); - if (removeFeature != null) { - ConnectionDecorator decorators[] = connection.getConnectionDecorators().toArray(new ConnectionDecorator[0]); - for (ConnectionDecorator decorator : decorators) { - if (decorator != null && (decorator.eResource() != null)) { - EcoreUtil.delete(decorator, true); - } - } - removeFeature.remove(rc); - } - } - } - } - } - - public void postRemove(IRemoveContext context) { - } - - @Override - public String getName() { - return NAME; - } - - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - - public void execute(IContext context) { - if (context instanceof IRemoveContext) { - remove((IRemoveContext)context); - } - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RenameEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RenameEntityFeature.java deleted file mode 100644 index 1258cfa79d..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RenameEntityFeature.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.ui.actions.RenameAction; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchSite; - - - -public class RenameEntityFeature extends RefactorEntityFeature { - - public RenameEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public void execute(ICustomContext context) { - ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt); - IWorkbenchSite ws = ((IEditorPart)getDiagramEditor()).getSite(); - RenameAction action = new RenameAction(ws); - ats = JpaArtifactFactory.instance().getRelatedAttributes(jpt); - execute(context, action, cu); - } - - @Override - public String getName() { - return JPAEditorMessages.RenameEntityFeature_ContextMenuOperationDescription; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RenameEntityWithoutUIFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RenameEntityWithoutUIFeature.java deleted file mode 100644 index 928be7c13f..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RenameEntityWithoutUIFeature.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.CustomContext; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class RenameEntityWithoutUIFeature extends RefactorEntityFeature { - - private String newName = null; - - public RenameEntityWithoutUIFeature(IFeatureProvider fp, String newName) { - super(fp); - this.newName = newName; - } - - public void execute(JavaPersistentType jpt) { - ICompilationUnit cu = getFeatureProvider().getCompilationUnit(jpt); - ats = JpaArtifactFactory.instance().getRelatedAttributes(jpt); - execute(new CustomContext(), newName, cu, jpt); - } - - public void execute(ICustomContext context) { - // not used - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ResizeAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ResizeAttributeFeature.java deleted file mode 100644 index 22308ab9f5..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ResizeAttributeFeature.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IContext; -import org.eclipse.graphiti.features.context.IResizeShapeContext; -import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature; - - -public class ResizeAttributeFeature extends DefaultResizeShapeFeature { - - public ResizeAttributeFeature(IFeatureProvider fp) { - super(fp); - } - - public boolean canResizeShape(IResizeShapeContext context) { - return false; - } - - - public boolean canExecute(IContext context) { - return false; - } - - - public boolean isAvailable(IContext context) { - return false; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ResizeJPAEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ResizeJPAEntityFeature.java deleted file mode 100644 index cbf59b93d2..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ResizeJPAEntityFeature.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IResizeShapeContext; -import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; - - -public class ResizeJPAEntityFeature extends DefaultResizeShapeFeature { - - public ResizeJPAEntityFeature(IFeatureProvider fp) { - super(fp); - } - - @Override - public boolean canResizeShape(IResizeShapeContext context) { - boolean canResize = super.canResizeShape(context); - if (canResize) { - Shape shape = context.getShape(); - Object bo = getBusinessObjectForPictogramElement(shape); - if (bo == null) return false; - if (bo instanceof PersistentType) { - PersistentType c = (PersistentType) bo; - if (c.getName() != null && - c.getName().length() == 1) { - canResize = false; - } - } - } - return canResize; - } - - private void resizeContainerShape(IResizeShapeContext context) { - super.resizeShape(context); - } - - public void resizeShape(final IResizeShapeContext context) { - final ContainerShape entityShape = (ContainerShape) context.getShape(); - TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(entityShape); - ted.getCommandStack().execute(new RecordingCommand(ted) { - protected void doExecute() { - resizeContainerShape(context); - JPAEditorUtil.rearrangeAllConnections(entityShape, - getFeatureProvider(), false); - } - }); - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RestoreEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RestoreEntityFeature.java deleted file mode 100644 index 60b67473b9..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RestoreEntityFeature.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.ui.PlatformUI; - - -public class RestoreEntityFeature extends AbstractCustomFeature { - - public RestoreEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public boolean canExecute(ICustomContext context) { - return true; - } - - public void execute(ICustomContext context) { - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(context.getPictogramElements()[0]); - if (JPAEditorUtil.isEntityOpenElsewhere(jpt, true)) { - String shortEntName = JPAEditorUtil - .returnSimpleName(JpaArtifactFactory.instance() - .getEntityName(jpt)); - String message = NLS.bind( - JPAEditorMessages.JPASolver_closeWarningMsg, shortEntName); - MessageDialog dialog = new MessageDialog(PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getShell(), - JPAEditorMessages.JPASolver_closeEditors, null, message, - MessageDialog.WARNING, - new String[] { JPAEditorMessages.BTN_OK }, 0) { - protected int getShellStyle() { - return SWT.CLOSE | SWT.TITLE | SWT.BORDER - | SWT.APPLICATION_MODAL | getDefaultOrientation(); - } - }; - dialog.open(); - return; - } - JpaArtifactFactory.instance().restoreEntityClass(jpt, getFeatureProvider()); - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_discardChangesMenuItem; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/SaveAndRemoveAllEntitiesFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/SaveAndRemoveAllEntitiesFeature.java deleted file mode 100644 index 9665d519e5..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/SaveAndRemoveAllEntitiesFeature.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Iterator; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.CustomContext; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.swt.widgets.Display; - - -public class SaveAndRemoveAllEntitiesFeature extends RemoveAllEntitiesFeature { - - public SaveAndRemoveAllEntitiesFeature(IFeatureProvider fp) { - super(fp); - } - - public String getConfirmationText() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAndSaveAllEntitiesConfirmation; - } - - - public void execute(ICustomContext context) { - MessageDialog dlg = new MessageDialog(Display.getCurrent().getShells()[0], - JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu, - null, getConfirmationText(), 0, - new String[] {JPAEditorMessages.BTN_OK, JPAEditorMessages.BTN_CANCEL}, Dialog.CANCEL); - if (dlg.open() != Dialog.OK) - return; - Iterator<Shape> it = this.getDiagram().getChildren().iterator(); - while (it.hasNext()) { - Shape sh = it.next(); - SaveEntityFeature ft = new SaveEntityFeature(getFeatureProvider()); - ICustomContext ctx = new CustomContext(new PictogramElement[] { sh }); - ft.execute(ctx); - allShapes.add(sh); - } - super.execute(context); - } - - @Override - public String getName() { - return JPAEditorMessages.SaveAndRemoveAllEntitiesFeature_ContextMenuOperationDescription; - } -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/SaveEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/SaveEntityFeature.java deleted file mode 100644 index 0189647cbf..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/SaveEntityFeature.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class SaveEntityFeature extends AbstractCustomFeature { - - public SaveEntityFeature(IFeatureProvider fp) { - super(fp); - } - - public boolean canExecute(ICustomContext context) { - return true; - } - - public void execute(ICustomContext context) { - JavaPersistentType jpt = (JavaPersistentType)getFeatureProvider().getBusinessObjectForPictogramElement(context.getPictogramElements()[0]); - JpaArtifactFactory.instance().forceSaveEntityClass(jpt, getFeatureProvider()); - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider)super.getFeatureProvider(); - } - - @Override - public String getName() { - return JPAEditorMessages.JPAEditorToolBehaviorProvider_saveMenuItem; - } - -} diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java deleted file mode 100644 index 853f916909..0000000000 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/UpdateAttributeFeature.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.internal.feature; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.features.context.impl.AddConnectionContext; -import org.eclipse.graphiti.features.context.impl.AddContext; -import org.eclipse.graphiti.features.custom.AbstractCustomFeature; -import org.eclipse.graphiti.mm.algorithms.Rectangle; -import org.eclipse.graphiti.mm.algorithms.Text; -import org.eclipse.graphiti.mm.algorithms.styles.Color; -import org.eclipse.graphiti.mm.algorithms.styles.Orientation; -import org.eclipse.graphiti.mm.pictograms.AnchorContainer; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; -import org.eclipse.graphiti.mm.pictograms.Shape; -import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; - - -public class UpdateAttributeFeature extends AbstractCustomFeature { - - public UpdateAttributeFeature(IFeatureProvider fp) { - super(fp); - } - - public void reconnect(JavaPersistentType jpt) { - IJPAEditorFeatureProvider fp = getFeatureProvider(); - Collection<IRelation> rels = JpaArtifactFactory.instance().produceAllRelations(jpt, fp); - JpaArtifactFactory.instance().refreshEntityModel(fp, jpt); - - Iterator<IRelation> it = rels.iterator(); - while (it.hasNext()) { - IRelation rel = it.next(); - AddRelationFeature relF = new AddRelationFeature(fp); - AnchorContainer acSource = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getOwner()); - AnchorContainer acTarget = (AnchorContainer) fp.getPictogramElementForBusinessObject(rel.getInverse()); - if ((acSource != null) && (acTarget != null)) { - AddConnectionContext ctx = new AddConnectionContext(acSource.getAnchors().iterator().next(), acTarget - .getAnchors().iterator().next()); - ctx.setNewObject(rel); - relF.add(ctx); - } - } - } - - /** - * @deprecated use the {@link GraphicalRemoveAttributeFeature} - */ - public void execute(ICustomContext context) { - GraphicalRemoveAttributeFeature remove = new GraphicalRemoveAttributeFeature(getFeatureProvider()); - remove.execute(context); - } - - /** - * @deprecated Use GraphicalAddAttributeFeature - * @param entityShape - * @param newAttr - * @return - */ - public ContainerShape addAttributes(ContainerShape entityShape, JavaPersistentAttribute newAttr) { - AddContext context = new AddContext(); - context.setNewObject(newAttr); - context.setTargetContainer(entityShape); - GraphicalAddAttributeFeature feature = new GraphicalAddAttributeFeature(getFeatureProvider()); - return (ContainerShape) feature.add(context); - } - - public IJPAEditorFeatureProvider getFeatureProvider() { - return (IJPAEditorFeatureProvider) super.getFeatureProvider(); - } - - public static Text addText(IFeatureProvider fp, Rectangle textRectangle, String txt) { - Text text = Graphiti.getGaService().createDefaultText(fp.getDiagramTypeProvider().getDiagram(), textRectangle, txt); - Color color = Graphiti.getGaService().manageColor(fp.getDiagramTypeProvider().getDiagram(), - JPAEditorConstants.ENTITY_TEXT_FOREGROUND); - text.setForeground(color); - text.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT); - text.setVerticalAlignment(Orientation.ALIGNMENT_TOP); - text.getFont().setBold(true); - return text; - } - - public static Rectangle addRectangleForText(ContainerShape cs, int attribIndex, int width) { - Rectangle rect = Graphiti.getGaService().createRectangle(cs); - rect.setFilled(false); - rect.setLineVisible(false); - rect.setHeight(JPAEditorConstants.ATTRIBUTE_RECT_HEIGHT); - rect.setWidth(width - JPAEditorConstants.ATTRIBUTE_TEXT_RECT_WIDTH_REDUCER); - rect.setX(JPAEditorConstants.ATTRIBUTE_TEXT_RECT_X); - rect - .setY(JPAEditorConstants.ATTRIBUTES_TOP_OFFSET + attribIndex - * JPAEditorConstants.ATTRIBUTES_PLACEMENT_STEP); - return rect; - } - - public static Rectangle addRectangleForIcon(ContainerShape cs, int attribIndex) { - Rectangle rect = Graphiti.getGaService().createRectangle(cs); - rect.setFilled(false); - rect.setLineVisible(false); - rect.setHeight(JPAEditorConstants.ICON_RECT_HEIGHT); - rect.setX(JPAEditorConstants.ICON_RECT_LEFT_OFFSET); - rect.setWidth(JPAEditorConstants.ICON_RECT_WIDTH); - rect - .setY(JPAEditorConstants.ATTRIBUTES_TOP_OFFSET + attribIndex - * JPAEditorConstants.ATTRIBUTES_PLACEMENT_STEP); - return rect; - } - - public void addSeparatorsToShape(ContainerShape compartmentShape) { - addSeparatorToCollection(compartmentShape, 0); - addSeparatorToCollection(compartmentShape, JPAEditorConstants.COMPARTMENT_MIN_HEIGHT); - } - - private Shape addSeparatorToCollection(ContainerShape containerShape, int y) { - final int width = containerShape.getGraphicsAlgorithm().getWidth(); - Shape shape = Graphiti.getPeService().createShape(containerShape, false); - Rectangle rectangle = Graphiti.getGaService().createRectangle(shape); - rectangle.setForeground(manageColor(JPAEditorConstants.ENTITY_BACKGROUND)); - rectangle.setBackground(manageColor(JPAEditorConstants.ENTITY_BORDER_COLOR)); - rectangle.setLineVisible(false); - Graphiti.getGaService().setSize(rectangle, width, JPAEditorConstants.SEPARATOR_HEIGHT); - Graphiti.getGaService().setLocationAndSize(rectangle, 0, y, width, JPAEditorConstants.SEPARATOR_HEIGHT); - return shape; - } -} |