This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 7c20057c758e9a7db8c8fd7d452fe698ab6b3cc8 Author: Andrus Adamchik <[email protected]> AuthorDate: Fri May 8 16:59:27 2026 -0400 CAY-2937 Decomission "graph" support * removing graph handling from the Modeler --- RELEASE-NOTES.txt | 1 + UPGRADE.txt | 4 + modeler/cayenne-modeler/pom.xml | 5 - .../org/apache/cayenne/modeler/ModelerModule.java | 2 - .../cayenne/modeler/graph/BaseGraphBuilder.java | 607 --------------------- .../modeler/graph/DbEntityCellMetadata.java | 49 -- .../cayenne/modeler/graph/DbGraphBuilder.java | 137 ----- .../cayenne/modeler/graph/EntityCellMetadata.java | 76 --- .../apache/cayenne/modeler/graph/GraphBuilder.java | 73 --- .../org/apache/cayenne/modeler/graph/GraphMap.java | 135 ----- .../cayenne/modeler/graph/GraphRegistry.java | 111 ---- .../apache/cayenne/modeler/graph/GraphType.java | 57 -- .../modeler/graph/ObjEntityCellMetadata.java | 50 -- .../cayenne/modeler/graph/ObjGraphBuilder.java | 211 ------- .../modeler/service/action/GlobalActions.java | 6 +- .../modeler/service/graph/EntityHandler.java | 60 -- .../modeler/service/graph/GraphExtension.java | 71 --- .../modeler/service/graph/GraphHandler.java | 94 ---- .../modeler/service/graph/GraphLoaderDelegate.java | 49 -- .../modeler/service/graph/GraphSaverDelegate.java | 69 --- .../modeler/service/graph/GraphsRootHandler.java | 55 -- .../project/editor/datadomain/DataDomainView.java | 15 +- .../datadomain/graph/DataDomainGraphTab.java | 196 ------- .../graph/action/EntityDisplayAction.java | 98 ---- .../graph/action/RebuildGraphAction.java | 48 -- .../graph/action/RemoveEntityAction.java | 67 --- .../datadomain/graph/action/SaveAsImageAction.java | 105 ---- .../graph/action/ShowGraphEntityAction.java | 93 ---- .../datadomain/graph/action/ZoomInAction.java | 51 -- .../datadomain/graph/action/ZoomOutAction.java | 51 -- .../editor/dbentity/main/DbEntityMainView.java | 3 - .../editor/objentity/main/ObjEntityMainView.java | 3 - pom.xml | 5 - 33 files changed, 7 insertions(+), 2650 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 7e7984591..2291f567c 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -35,6 +35,7 @@ CAY-2929 Modeler: Prefrences management UI CAY-2930 Modeler: remove "rename" button from DB Import toolbar CAY-2932 Remove "Generate Classes" menu CAY-2933 Modeler: DB Type Column Unreadable for Selected Rows +CAY-2937 Decommission "graph" Support Bug Fixes: diff --git a/UPGRADE.txt b/UPGRADE.txt index a139d4b82..931c5b1bb 100644 --- a/UPGRADE.txt +++ b/UPGRADE.txt @@ -7,6 +7,10 @@ IMPORTANT: be sure to read all notes for the intermediate releases between your UPGRADING TO 5.0.M2 +* Per CAY-2937 the visual graph feature (entity layout diagrams) has been removed from CayenneModeler. +Existing `.graph.xml` files will be automatically deleted and their `<xi:include>` references removed +from `cayenne-project.xml` when a project is opened and upgraded to format version 12. + * Per CAY-2859 SelectById query factory methods are redesigned with a bunch of old methods deprecated, so you should update your calls accordingly. diff --git a/modeler/cayenne-modeler/pom.xml b/modeler/cayenne-modeler/pom.xml index d71aefe66..721460f3b 100644 --- a/modeler/cayenne-modeler/pom.xml +++ b/modeler/cayenne-modeler/pom.xml @@ -73,11 +73,6 @@ <version>${project.version}</version> </dependency> - <dependency> - <groupId>jgraph</groupId> - <artifactId>jgraph</artifactId> - </dependency> - <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ModelerModule.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ModelerModule.java index 1b817283c..900117158 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ModelerModule.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ModelerModule.java @@ -28,7 +28,6 @@ import org.apache.cayenne.di.Module; import org.apache.cayenne.gen.xml.CgenExtension; import org.apache.cayenne.modeler.pref.PreferencesRepository; import org.apache.cayenne.modeler.service.action.GlobalActions; -import org.apache.cayenne.modeler.service.graph.GraphExtension; import org.apache.cayenne.modeler.service.platform.DefaultPlatformInitializer; import org.apache.cayenne.modeler.service.platform.PlatformInitializer; import org.apache.cayenne.modeler.service.classloader.ModelerClassLoader; @@ -59,7 +58,6 @@ public class ModelerModule implements Module { ProjectModule.extend(binder) .addExtension(InfoExtension.class) - .addExtension(GraphExtension.class) .addExtension(DbImportExtension.class) .addExtension(CgenExtension.class) .addExtension(ValidationExtension.class); diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java deleted file mode 100644 index f07847fb4..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java +++ /dev/null @@ -1,607 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Point; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.swing.JPopupMenu; -import javax.swing.border.LineBorder; -import javax.swing.event.UndoableEditEvent; - -import org.apache.cayenne.configuration.ConfigurationNodeVisitor; -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.modeler.event.model.DataMapEvent; -import org.apache.cayenne.modeler.event.model.DataMapListener; -import org.apache.cayenne.modeler.event.model.ModelEvent; -import org.apache.cayenne.map.Attribute; -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.map.Entity; -import org.apache.cayenne.map.Relationship; -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.apache.cayenne.modeler.service.action.GlobalActions; -import org.apache.cayenne.modeler.ui.action.CreateAttributeAction; -import org.apache.cayenne.modeler.ui.action.CreateRelationshipAction; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.EntityDisplayAction; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.RemoveEntityAction; -import org.apache.cayenne.util.XMLEncoder; -import org.jgraph.JGraph; -import org.jgraph.graph.AttributeMap; -import org.jgraph.graph.DefaultCellViewFactory; -import org.jgraph.graph.DefaultEdge; -import org.jgraph.graph.DefaultGraphCell; -import org.jgraph.graph.DefaultGraphModel; -import org.jgraph.graph.GraphConstants; -import org.jgraph.graph.GraphLayoutCache; -import org.jgraph.graph.GraphModel; - -import com.jgraph.layout.JGraphFacade; -import com.jgraph.layout.organic.JGraphOrganicLayout; - -/** - * Base class for building graphs of entities - */ -abstract class BaseGraphBuilder<E extends Entity<E, A, R>, A extends Attribute<E, A, R>, R extends Relationship<E, A, R>> - implements GraphBuilder<E, A, R>, DataMapListener { - - static final Font EDGE_FONT = new Font("Verdana", Font.PLAIN, 10); - - /** - * Graph - */ - protected JGraph graph; - - /** - * Domain - */ - protected transient DataChannelDescriptor domain; - - /** - * Created entity cells. Maps to entity name, since GraphBuilder can be - * serialized - */ - protected Map<String, DefaultGraphCell> entityCells; - - /** - * Created relationship cells Maps to relationship qualified name, since - * GraphBuilder can be serialized - */ - protected Map<String, DefaultEdge> relCells; - - /** - * Created non-isolated objects - */ - protected List<DefaultGraphCell> createdObjects; - - protected transient ProjectSession session; - - protected transient Entity<E, A, R> selectedEntity; - - transient JPopupMenu popup; - - boolean undoEventsDisabled; - - @Override - public void buildGraph(ProjectSession session, DataChannelDescriptor domain, boolean doLayout) { - if (graph != null) { - // graph already built, exiting silently - return; - } - - graph = new JGraph(); - GraphModel model = new DefaultGraphModel(); - graph.setModel(model); - - setProjectSession(session); - setDataDomain(domain); - - GraphLayoutCache view = new GraphLayoutCache(model, new DefaultCellViewFactory()); - graph.setGraphLayoutCache(view); - - addMouseListeners(); - - entityCells = new HashMap<>(); - createdObjects = new ArrayList<>(); - relCells = new HashMap<>(); - - /* - * an array for entities that are not connected to anyone. We add them - * separately so that layout doesn't touch them - */ - List<DefaultGraphCell> isolatedObjects = new ArrayList<>(); - - /* - * 1. Add all entities - */ - for (DataMap map : domain.getDataMaps()) { - DefaultGraphCell mapCell = new DefaultGraphCell(); - createdObjects.add(mapCell); - - for (E entity : getEntities(map)) { - DefaultGraphCell cell = createEntityCell(entity); - - // mapCell.add(cell); - // cell.setParent(mapCell); - - List<DefaultGraphCell> array = !isIsolated(domain, entity) ? createdObjects : isolatedObjects; - array.add(cell); - array.add((DefaultGraphCell) cell.getChildAt(0)); // port - } - } - - /* - * 2. Add all relationships - */ - for (DataMap map : domain.getDataMaps()) { - for (E entity : getEntities(map)) { - DefaultGraphCell sourceCell = entityCells.get(entity.getName()); - - postProcessEntity(entity, sourceCell); - } - } - view.insert(createdObjects.toArray()); - - setLayout(doLayout); - - /* - * Adding isolated objects - * - * We're placing them so that they will take maximum space in left top - * corner. The sample order is below: - * - * 1 2 6 7... 3 5 8 ... 4 9... 10 ... - */ - addIsolatedObjects(isolatedObjects); - - view.insert(isolatedObjects.toArray()); - graph.getModel().addUndoableEditListener(this); - } - - private void setLayout(boolean doLayout) { - if (doLayout) { - JGraphFacade facade = new JGraphFacade(graph); - - JGraphOrganicLayout layout = new JGraphOrganicLayout(); - layout.setNodeDistributionCostFactor(5000000000000.0); - layout.setEdgeLengthCostFactor(1000); - layout.setEdgeCrossingCostFactor(1000000); - layout.setOptimizeBorderLine(false); - layout.setOptimizeEdgeDistance(false); - - // JGraphHierarchicalLayout layout = new JGraphHierarchicalLayout(); - // layout.setInterHierarchySpacing(150.0); - // layout.setIntraCellSpacing(150.0); - // layout.setInterRankCellSpacing(150.0); - - // JGraphSimpleLayout layout = new JGraphSimpleLayout(JGraphSimpleLayout.TYPE_TILT, 4000, 2000); - layout.run(facade); - // Obtain a map of the resulting attribute changes from the facade - Map<?,?> nested = facade.createNestedMap(true, true); - - // Apply the results to the actual graph - edit(nested); - } - } - - private void addMouseListeners() { - graph.addMouseListener(new MouseAdapter() { - @SuppressWarnings("unchecked") - @Override - public void mouseReleased(MouseEvent e) { - if (e.isPopupTrigger()) { - Object selected = graph.getSelectionCell(); - if (selected instanceof DefaultGraphCell) { - Object userObject = ((DefaultGraphCell) selected).getUserObject(); - if (userObject instanceof EntityCellMetadata) { - showPopup(e.getPoint(), ((EntityCellMetadata<E,A,R>) userObject).fetchEntity()); - } - } - } - } - }); - - graph.addMouseWheelListener(e -> { - // limit scale - double scale = graph.getScale() / Math.pow(ZOOM_FACTOR, e.getWheelRotation()); - scale = Math.max(scale, 0.1); - scale = Math.min(scale, 3); - graph.setScale(scale); - }); - } - - private void addIsolatedObjects(List<DefaultGraphCell> isolatedObjects) { - if (isolatedObjects.size() > 0) { - int n = isolatedObjects.size() / 2; // number of isolated entities - int x = (int) Math.ceil((Math.sqrt(1 + 8 * n) - 1) / 2); // side of - // triangle - - Dimension pref = graph.getPreferredSize(); - int dx = pref.width / 2 / x; // x-distance between entities - int dy = pref.height / 2 / x; // y-distance between entities - - int posX = dx / 2; - int posY = dy / 2; - - int row = 0; - - for (int isolatedIndex = 0; isolatedIndex < isolatedObjects.size();) { - for (int i = 0; isolatedIndex < isolatedObjects.size() && i < x - row; i++) { - GraphConstants.setBounds(isolatedObjects.get(isolatedIndex).getAttributes(), - new Rectangle2D.Double(pref.width - posX, pref.height - (3.0 * posY) / 2, 10, 10)); - isolatedIndex += 2; // because every 2nd object is port - posX += dx; - } - posX = dx / 2; - posY += dy / 2; - row++; - } - } - } - - protected DefaultGraphCell createEntityCell(E entity) { - DefaultGraphCell cell = new DefaultGraphCell(getCellMetadata(entity)); - - GraphConstants.setResize(cell.getAttributes(), true); - GraphConstants.setBorder(cell.getAttributes(), new LineBorder(Color.BLACK)); - - GraphConstants.setEditable(cell.getAttributes(), false); - entityCells.put(entity.getName(), cell); - - cell.addPort(); - return cell; - } - - @Override - public DefaultGraphCell getEntityCell(String entityName) { - return entityCells.get(entityName); - } - - /** - * Post (i.e. after creation on entity cell) process of the entity - */ - protected void postProcessEntity(E entity, DefaultGraphCell cell) { - for (R rel : entity.getRelationships()) { - if (rel.getSourceEntity() != null && rel.getTargetEntity() != null) { - DefaultEdge edge = createRelationshipCell(rel); - if (edge != null) { - createdObjects.add(edge); - } - } - } - } - - /** - * Returns whether an entity is not connected to any other - * TODO: not fine algorithm, it iterates through all entities and all rels - */ - protected boolean isIsolated(DataChannelDescriptor domain, E entity) { - if (entity.getRelationships().size() == 0) { - // searching for rels that have a target="entity" - - for (DataMap map : domain.getDataMaps()) { - for (E source : getEntities(map)) { - if (source.getAnyRelationship(entity) != null) { - return false; - } - } - } - return true; - } - return false; - } - - protected abstract Collection<E> getEntities(DataMap map); - - /** - * Returns label for relationship on the graph, considering its "mandatory" - * and "to-many" properties - */ - private static <E extends Entity<E, A, R>, A extends Attribute<E, A, R>, R extends Relationship<E, A, R>> - String getRelationshipLabel(Relationship<E, A, R> rel) { - if (rel == null) { - return null; - } - - if (rel.isToMany()) { - return "0..*"; - } - return rel.isMandatory() ? "1" : "0..1"; - } - - /** - * Returns metadata (user object) for this cell - */ - protected abstract EntityCellMetadata<E, A, R> getCellMetadata(E e); - - protected void showPopup(Point p, Entity<E, A, R> entity) { - selectedEntity = entity; - if (popup == null) { - popup = createPopupMenu(); - } - popup.show(graph, p.x, p.y); - } - - @Override - public Entity<E, A, R> getSelectedEntity() { - return selectedEntity; - } - - /** - * Creates popup menu - */ - protected JPopupMenu createPopupMenu() { - Application application = session.app(); - GlobalActions globalActions = application.getActionManager(); - - JPopupMenu menu = new JPopupMenu(); - menu.add(new EntityDisplayAction(this, application).buildMenu()); - menu.addSeparator(); - menu.add(new EntityDisplayAction(this, globalActions.getAction(CreateAttributeAction.class), application).buildMenu()); - menu.add(new EntityDisplayAction(this, globalActions.getAction(CreateRelationshipAction.class), application).buildMenu()); - menu.addSeparator(); - menu.add(new RemoveEntityAction(this, application)); - - return menu; - } - - /** - * Updates specified entity on the graph - */ - protected void updateEntityCell(E e) { - DefaultGraphCell cell = entityCells.get(e.getName()); - if (cell != null) { - GraphConstants.setValue(cell.getAttributes(), getCellMetadata(e)); - GraphConstants.setResize(cell.getAttributes(), true); - - Map<DefaultGraphCell, AttributeMap> nested = new HashMap<>(); - nested.put(cell, cell.getAttributes()); - - edit(nested); - } - } - - protected void updateRelationshipCell(R rel) { - if (rel.getSourceEntity() != null && rel.getTargetEntity() != null) { - DefaultEdge edge = relCells.get(getQualifiedName(rel)); - if (edge != null) { - updateRelationshipLabels(edge, rel, rel.getReverseRelationship()); - - Map<DefaultEdge, AttributeMap> nested = new HashMap<>(); - nested.put(edge, edge.getAttributes()); - edit(nested); - } else { - insertRelationshipCell(rel); - } - } - } - - protected void removeEntityCell(E e) { - final DefaultGraphCell cell = entityCells.get(e.getName()); - if (cell != null) { - runWithUndoDisabled(() -> graph.getGraphLayoutCache().remove(new Object[] { cell }, true, true)); - entityCells.remove(e.getName()); - } - } - - protected void removeRelationshipCell(R rel) { - final DefaultEdge edge = relCells.get(getQualifiedName(rel)); - if (edge != null) { - runWithUndoDisabled(() -> graph.getGraphLayoutCache().remove(new Object[] { edge })); - relCells.remove(getQualifiedName(rel)); - } - } - - protected DefaultEdge createRelationshipCell(R rel) { - if (!relCells.containsKey(getQualifiedName(rel))) { - Relationship<E, A, R> reverse = rel.getReverseRelationship(); - - DefaultEdge edge = new DefaultEdge(); - - // GraphConstants.setLineStyle(edge.getAttributes(), - // GraphConstants.STYLE_ORTHOGONAL); - // GraphConstants.setRouting(edge.getAttributes(), - // GraphConstants.ROUTING_SIMPLE); - - GraphConstants.setEditable(edge.getAttributes(), false); - GraphConstants.setLabelAlongEdge(edge.getAttributes(), true); - GraphConstants.setSelectable(edge.getAttributes(), false); - GraphConstants.setFont(edge.getAttributes(), EDGE_FONT); - - updateRelationshipLabels(edge, rel, reverse); - - relCells.put(getQualifiedName(rel), edge); - - if (reverse != null) { - relCells.put(getQualifiedName(reverse), edge); - } - - return edge; - } - return null; - } - - protected void insertRelationshipCell(R rel) { - DefaultEdge edge = createRelationshipCell(rel); - insert(edge); - } - - protected void insertEntityCell(E entity) { - DefaultGraphCell cell = createEntityCell(entity); - - // putting cell to a random posistion.. - GraphConstants.setBounds(cell.getAttributes(), - new Rectangle2D.Double(Math.random() * graph.getWidth(), Math.random() * graph.getHeight(), 10, 10)); - - // setting graph type-specific attrs - postProcessEntity(entity, cell); - - insert(cell); - } - - /** - * Updates relationship labels for specified relationship edge. - */ - protected void updateRelationshipLabels(DefaultEdge edge, Relationship<E, A, R> rel, Relationship<E, A, R> reverse) { - DefaultGraphCell sourceCell = entityCells.get(rel.getSourceEntity().getName()); - DefaultGraphCell targetCell = entityCells.get(rel.getTargetEntity().getName()); - - edge.setSource(sourceCell != null ? sourceCell.getChildAt(0) : null); - edge.setTarget(targetCell != null ? targetCell.getChildAt(0) : null); - - Object[] labels = { rel.getName() + " " + getRelationshipLabel(rel), - reverse == null ? "" : reverse.getName() + " " + getRelationshipLabel(reverse) }; - GraphConstants.setExtraLabels(edge.getAttributes(), labels); - - Point2D[] labelPositions = { - new Point2D.Double(GraphConstants.PERMILLE * (0.1 + 0.2 * Math.random()), 10), - new Point2D.Double(GraphConstants.PERMILLE * (0.9 - 0.2 * Math.random()), -10) - }; - GraphConstants.setExtraLabelPositions(edge.getAttributes(), labelPositions); - } - - @Override - public JGraph getGraph() { - return graph; - } - - @Override - public void dataMapAdded(DataMapEvent e) { - } - - @Override - public void dataMapChanged(DataMapEvent e) { - } - - @Override - public void dataMapRemoved(DataMapEvent e) { - for (E entity : getEntities(e.getDataMap())) { - removeEntityCell(entity); - } - } - - public void setProjectSession(ProjectSession session) { - this.session = session; - - session.addDataMapListener(this); - } - - public void setDataDomain(DataChannelDescriptor domain) { - this.domain = domain; - } - - @Override - public DataChannelDescriptor getDataDomain() { - return domain; - } - - @Override - public void destroy() { - session.removeDataMapListener(this); - } - - /** - * Checks if entity name has changed, then changes map key - */ - protected void remapEntity(ModelEvent e) { - if (e.isNameChange()) { - entityCells.put(e.getNewName(), entityCells.remove(e.getOldName())); - } - } - - /** - * Checks if relationship name has changed, then changes map key - */ - @SuppressWarnings("unchecked") - protected void remapRelationship(Relationship<E, A, R> relationship, ModelEvent e, String entityName) { - if (e.isNameChange()) { - relCells.put(getQualifiedName(relationship), - relCells.remove(entityName + "." + e.getOldName())); - } - } - - /** - * Returns qualified name (entity name + relationship name) for a - * relationship - */ - static <E extends Entity<E, A, R>, A extends Attribute<E, A, R>, R extends Relationship<E, A, R>> - String getQualifiedName(Relationship<E, A, R> rel) { - return rel.getSourceEntity().getName() + "." + rel.getName(); - } - - @Override - public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate) { - encoder.start("graph") - .attribute("type", getType().toString()) - .attribute("scale", String.valueOf(graph.getScale())); - - for (Entry<String, DefaultGraphCell> entry : entityCells.entrySet()) { - Rectangle2D rect = graph.getCellBounds(entry.getValue()); - - encoder.start("entity") - .attribute("name", entry.getKey()) - .attribute("x", String.valueOf(Math.round(100 * rect.getX()) / 100.0)) - .attribute("y", String.valueOf(Math.round(100 * rect.getY()) / 100.0)) - .attribute("width", String.valueOf(rect.getWidth())) - .attribute("height", String.valueOf(rect.getHeight())) - .end(); - } - - encoder.end(); - } - - private void edit(final Map<?,?> map) { - runWithUndoDisabled(() -> graph.getGraphLayoutCache().edit(map)); - } - - private void insert(final Object cell) { - runWithUndoDisabled(() -> graph.getGraphLayoutCache().insert(cell)); - } - - private void runWithUndoDisabled(Runnable r) { - undoEventsDisabled = true; - try { - r.run(); - } finally { - undoEventsDisabled = false; - } - } - - @Override - public void undoableEditHappened(UndoableEditEvent e) { - if (!undoEventsDisabled) { - // graph has been modified - session.setDirty(true); - - session.app().getUndoManager().undoableEditHappened(e); - } - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DbEntityCellMetadata.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DbEntityCellMetadata.java deleted file mode 100644 index 3d87bdf99..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DbEntityCellMetadata.java +++ /dev/null @@ -1,49 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.map.DbAttribute; -import org.apache.cayenne.map.DbEntity; -import org.apache.cayenne.map.DbRelationship; - -/** - * Descriptor of DbEntity Cell - */ -class DbEntityCellMetadata extends EntityCellMetadata<DbEntity, DbAttribute, DbRelationship> { - DbEntityCellMetadata(DbGraphBuilder builder, DbEntity entity) { - super(builder, entity); - } - - @Override - public DbEntity fetchEntity() { - for (DataMap dm : builder.getDataDomain().getDataMaps()) { - DbEntity dbEntity =dm.getDbEntity(entityName) ; - if (dbEntity!= null) { - return dbEntity; - } - } - return null; - } - - @Override - protected boolean isPrimary(DbAttribute attr) { - return attr.isPrimaryKey(); - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DbGraphBuilder.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DbGraphBuilder.java deleted file mode 100644 index 3130c69a1..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DbGraphBuilder.java +++ /dev/null @@ -1,137 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import java.awt.Color; -import java.util.Collection; - -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.dbsync.model.DetectedDbEntity; -import org.apache.cayenne.map.DbAttribute; -import org.apache.cayenne.map.DbEntity; -import org.apache.cayenne.map.DbRelationship; -import org.apache.cayenne.modeler.event.model.DbRelationshipEvent; -import org.apache.cayenne.modeler.event.model.DbEntityEvent; -import org.apache.cayenne.modeler.event.model.DbAttributeEvent; -import org.apache.cayenne.modeler.event.model.DbAttributeListener; -import org.apache.cayenne.modeler.event.model.DbEntityListener; -import org.apache.cayenne.modeler.event.model.DbRelationshipListener; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.jgraph.graph.DefaultEdge; -import org.jgraph.graph.DefaultGraphCell; -import org.jgraph.graph.GraphConstants; - -/** - * Class for building ER-graph, based on DbEntity information - */ -class DbGraphBuilder extends BaseGraphBuilder<DbEntity, DbAttribute, DbRelationship> implements DbEntityListener, DbAttributeListener, DbRelationshipListener { - - static final Color ENTITY_COLOR = new Color(197, 253, 252); - - @Override - protected Collection<DbEntity> getEntities(DataMap map) { - return map.getDbEntities(); - } - - @Override - protected void postProcessEntity(DbEntity entity, DefaultGraphCell cell) { - super.postProcessEntity(entity, cell); - - GraphConstants.setBackground(cell.getAttributes(), ENTITY_COLOR); - GraphConstants.setOpaque(cell.getAttributes(), true); - } - - @Override - protected DbEntityCellMetadata getCellMetadata(DbEntity e) { - return new DbEntityCellMetadata(this, e); - } - - @Override - protected DefaultEdge createRelationshipCell(DbRelationship rel) { - DefaultEdge edge = super.createRelationshipCell(rel); - if (edge != null) { - GraphConstants.setDashPattern(edge.getAttributes(), new float[] {10, 3}); - } - return edge; - } - - @Override - public void setProjectSession(ProjectSession session) { - super.setProjectSession(session); - - session.addDbEntityListener(this); - session.addDbAttributeListener(this); - session.addDbRelationshipListener(this); - } - - public void destroy() { - super.destroy(); - - session.removeDbEntityListener(this); - session.removeDbAttributeListener(this); - session.removeDbRelationshipListener(this); - } - - public void dbEntityAdded(DbEntityEvent e) { - // skip new entities from DbLoader - if(e.getEntity() instanceof DetectedDbEntity) { - return; - } - insertEntityCell((DbEntity) e.getEntity()); - } - - public void dbEntityChanged(DbEntityEvent e) { - remapEntity(e); - - updateEntityCell((DbEntity)e.getEntity()); - } - - public void dbEntityRemoved(DbEntityEvent e) { - removeEntityCell((DbEntity) e.getEntity()); - } - - public void dbAttributeAdded(DbAttributeEvent e) { - updateEntityCell((DbEntity)e.getEntity()); - } - - public void dbAttributeChanged(DbAttributeEvent e) { - updateEntityCell((DbEntity)e.getEntity()); - } - - public void dbAttributeRemoved(DbAttributeEvent e) { - updateEntityCell((DbEntity)e.getEntity()); - } - - public void dbRelationshipAdded(DbRelationshipEvent e) { - // nothing because relationship does not have target yet - } - - public void dbRelationshipChanged(DbRelationshipEvent e) { - updateRelationshipCell((DbRelationship) e.getRelationship()); - } - - public void dbRelationshipRemoved(DbRelationshipEvent e) { - remapRelationship(e.getRelationship(), e, e.getEntity().getName()); - removeRelationshipCell(e.getRelationship()); - } - - public GraphType getType() { - return GraphType.ER; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/EntityCellMetadata.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/EntityCellMetadata.java deleted file mode 100644 index 8d6060517..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/EntityCellMetadata.java +++ /dev/null @@ -1,76 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import java.io.Serializable; -import java.util.Objects; - -import org.apache.cayenne.map.Attribute; -import org.apache.cayenne.map.Entity; -import org.apache.cayenne.map.Relationship; - -/** - * Abstract class to describe entity's cell - */ -abstract class EntityCellMetadata<E extends Entity<E, A, R>, A extends Attribute<E, A, R>, R extends Relationship<E, A, R>> - implements Serializable { - final GraphBuilder<E,A,R> builder; - final String entityName; - final String label; - - EntityCellMetadata(GraphBuilder<E,A,R> builder, Entity<E,A,R> entity) { - this.builder = Objects.requireNonNull(builder); - this.entityName = Objects.requireNonNull(entity).getName(); - this.label = createLabel(entity); - } - - /** - * Resolves entity - */ - public abstract Entity<E, A, R> fetchEntity(); - - public String toString() { - return label; - } - - /** - * Creates label for this cell - */ - String createLabel(Entity<E, A, R> entity) { - StringBuilder label = new StringBuilder("<html><center><u><b>") - .append(entity.getName()) - .append("</b></u></center>"); - for (A attr : entity.getAttributes()) { - if (isPrimary(attr)) { - label.append("<br><i>").append(attr.getName()).append("</i>"); - } - } - for (A attr : entity.getAttributes()) { - if (!isPrimary(attr)) { - label.append("<br>").append(attr.getName()); - } - } - return label.append("</html>").toString(); - } - - /** - * Returns whether attribute is "primary" and should therefore be written in italic - */ - protected abstract boolean isPrimary(A attr); -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphBuilder.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphBuilder.java deleted file mode 100644 index c837f8f86..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import javax.swing.event.UndoableEditListener; - -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.map.Attribute; -import org.apache.cayenne.map.Entity; -import org.apache.cayenne.map.Relationship; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.apache.cayenne.util.XMLSerializable; -import org.jgraph.JGraph; -import org.jgraph.graph.DefaultGraphCell; - -/** - * Interface for building graphs which represent some perspective of a domain - */ -public interface GraphBuilder<E extends Entity<E, A, R>, A extends Attribute<E, A, R>, R extends Relationship<E, A, R>> extends XMLSerializable, UndoableEditListener { - - double ZOOM_FACTOR = 1.3; - - /** - * Builds graph - */ - void buildGraph(ProjectSession session, DataChannelDescriptor domain, boolean layout); - - /** - * Invoked at destroying of the builder - */ - void destroy(); - - /** - * Returns built graph for this builder - */ - JGraph getGraph(); - - /** - * Returns domain. - */ - DataChannelDescriptor getDataDomain(); - - /** - * Returns type of the graph - */ - GraphType getType(); - - /** - * Returns selected entity, <code>null</code> if none is selected - */ - Entity<E,A,R> getSelectedEntity(); - - /** - * Returns cell of an entity - */ - DefaultGraphCell getEntityCell(String entityName); -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphMap.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphMap.java deleted file mode 100644 index aab42dbeb..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphMap.java +++ /dev/null @@ -1,135 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.undo.UndoableEdit; - -import org.apache.cayenne.CayenneRuntimeException; -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.jgraph.graph.DefaultGraphCell; - -/** - * Map that stores graph builders <b>for a single domain</b> by their type - * and has additional methods to set currently selected graph and serialize to XML - */ -public class GraphMap extends HashMap<GraphType, GraphBuilder> { - /** - * type that is currently selected - */ - GraphType selectedType; - - /** - * Domain - */ - DataChannelDescriptor domain; - - /** - * Graph state parsed from the project XML and waiting for a {@link GraphBuilder} - * to be created — applied at first {@link #createGraphBuilder} for a given type. - * Kept off the live event bus so XML load doesn't subscribe to a not-yet-open project. - */ - private final Map<GraphType, ParkedState> parkedStates = new EnumMap<>(GraphType.class); - - public GraphMap(DataChannelDescriptor domain) { - this.domain = domain; - } - - /** - * Returns domain - */ - public DataChannelDescriptor getDomain() { - return domain; - } - - /** - * Returns type that is currently selected - */ - public GraphType getSelectedType() { - return selectedType; - } - - /** - * Sets type that is currently selected - */ - public void setSelectedType(GraphType selectedType) { - this.selectedType = selectedType; - } - - public GraphBuilder createGraphBuilder(ProjectSession session, GraphType type, boolean doLayout) { - try { - ParkedState parked = parkedStates.remove(type); - GraphBuilder builder = type.getBuilderClass().getDeclaredConstructor().newInstance(); - builder.buildGraph(session, domain, doLayout && parked == null); - if (parked != null) { - parked.applyTo(builder); - } - put(type, builder); - - return builder; - } catch (Exception e) { - throw new CayenneRuntimeException("Could not instantiate GraphBuilder", e); - } - } - - /** - * Stashes graph state parsed from the project XML for a given type. The state is - * applied to a freshly built {@link GraphBuilder} the first time - * {@link #createGraphBuilder} is invoked for that type. - */ - public void parkParsedState(GraphType type, double scale, Map<String, Map<String, ?>> entityProperties) { - parkedStates.put(type, new ParkedState(scale, entityProperties)); - } - - /** - * Returns true if there is parsed state waiting to be applied for the given type. - */ - public boolean hasParkedState(GraphType type) { - return parkedStates.containsKey(type); - } - - private static final class ParkedState { - private final double scale; - private final Map<String, Map<String, ?>> entityProperties; - - ParkedState(double scale, Map<String, Map<String, ?>> entityProperties) { - this.scale = scale; - this.entityProperties = entityProperties; - } - - void applyTo(GraphBuilder builder) { - builder.getGraph().setScale(scale); - - Map<DefaultGraphCell, Map<String, ?>> cellProperties = new HashMap<>(); - for (Map.Entry<String, Map<String, ?>> entry : entityProperties.entrySet()) { - DefaultGraphCell cell = builder.getEntityCell(entry.getKey()); - cellProperties.put(cell, entry.getValue()); - } - - // apply without polluting the undo stack - builder.getGraph().getGraphLayoutCache().getModel().removeUndoableEditListener(builder); - builder.getGraph().getGraphLayoutCache().edit(cellProperties, null, null, new UndoableEdit[0]); - builder.getGraph().getGraphLayoutCache().getModel().addUndoableEditListener(builder); - } - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphRegistry.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphRegistry.java deleted file mode 100644 index a5384de22..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphRegistry.java +++ /dev/null @@ -1,111 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.modeler.event.model.DomainEvent; -import org.apache.cayenne.modeler.event.model.DomainListener; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.jgraph.JGraph; - -import java.util.HashMap; -import java.util.Map; - -/** - * Class for storing information about datadomain's builders. - * Has methods for saving and loading graphs, as well as building graph for - * specified data domain. - * This class is center of all graph management in CM - */ -public class GraphRegistry implements DomainListener { - - /** - * Main storage of graph builders - */ - Map<DataChannelDescriptor, GraphMap> graphMaps; - - public GraphRegistry() { - graphMaps = new HashMap<>(); - } - - /** - * Builds graph with specified type, or returns existing one - */ - public JGraph loadGraph(ProjectSession session, DataChannelDescriptor domain, GraphType type) { - GraphMap graphMap = graphMaps.get(domain); - if (graphMap == null) { - graphMap = new GraphMap(domain); - graphMaps.put(domain, graphMap); - } - - GraphBuilder builder = graphMap.get(type); - if (builder == null) { - boolean fromParkedState = graphMap.hasParkedState(type); - builder = graphMap.createGraphBuilder(session, type, true); - - // only mark dirty when this is a freshly auto-laid-out graph; restoring a - // graph parsed from the project file shouldn't dirty the project - if (!fromParkedState) { - session.setDirty(true); - } - } - - //marking this builder as default - graphMap.setSelectedType(builder.getType()); - - return builder.getGraph(); - } - - /** - * Gets graph map for specified domain, creating it if needed - */ - public GraphMap getGraphMap(DataChannelDescriptor domain) { - GraphMap map = graphMaps.get(domain); - if (map == null) { - map = new GraphMap(domain); - graphMaps.put(domain, map); - } - return map; - } - - public void addGraphMap(DataChannelDescriptor domain, GraphMap map) { - graphMaps.put(domain, map); - } - - public void domainChanged(DomainEvent e) { - } - - void unregisterDomain(DataChannelDescriptor dataChannelDescriptor) { - GraphMap map = graphMaps.get(dataChannelDescriptor); - if (map != null) { - for (GraphBuilder builder : map.values()) { - builder.destroy(); - } - graphMaps.remove(dataChannelDescriptor); - } - } - - /** - * Removes all listeners (and itself) from ProjectSession - */ - public void unregister(ProjectSession session) { - unregisterDomain((DataChannelDescriptor)session.project().getRootNode()); - session.removeDomainListener(this); - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphType.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphType.java deleted file mode 100644 index d3dd89faf..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/GraphType.java +++ /dev/null @@ -1,57 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -/** - * Types of the graph - */ -public enum GraphType { - /** - * ER-diagram (with DbEntities) - */ - ER("ER Diagram", DbGraphBuilder.class), - - /** - * Obj-Diagram (with ObjEntities) - */ - CLASS("Class Diagram", ObjGraphBuilder.class); - - /** - * Class to build graphs with - */ - Class<? extends GraphBuilder> builderClass; - - /** - * Readable name - */ - String name; - - private GraphType(String name, Class builderClass) { - this.builderClass = builderClass; - this.name = name; - } - - public Class<? extends GraphBuilder> getBuilderClass() { - return builderClass; - } - - public String getName() { - return name; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/ObjEntityCellMetadata.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/ObjEntityCellMetadata.java deleted file mode 100644 index ad66804bc..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/ObjEntityCellMetadata.java +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.map.ObjAttribute; -import org.apache.cayenne.map.ObjEntity; -import org.apache.cayenne.map.ObjRelationship; - -/** - * Descriptor of ObjEntity Cell - */ -class ObjEntityCellMetadata extends EntityCellMetadata<ObjEntity, ObjAttribute, ObjRelationship> { - ObjEntityCellMetadata(ObjGraphBuilder builder, ObjEntity entity) { - super(builder, entity); - } - - @Override - public ObjEntity fetchEntity() { - for (DataMap dm : builder.getDataDomain().getDataMaps()) { - ObjEntity objEntity = dm.getObjEntity(entityName); - if (objEntity != null) { - return objEntity; - } - } - return null; - } - - @Override - protected boolean isPrimary(ObjAttribute attr) { - return false; - } - -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/ObjGraphBuilder.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/ObjGraphBuilder.java deleted file mode 100644 index 5d93ab235..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/ObjGraphBuilder.java +++ /dev/null @@ -1,211 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.graph; - -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.map.EntityInheritanceTree; -import org.apache.cayenne.map.EntityResolver; -import org.apache.cayenne.map.ObjAttribute; -import org.apache.cayenne.map.ObjEntity; -import org.apache.cayenne.map.ObjRelationship; -import org.apache.cayenne.modeler.event.model.ObjRelationshipEvent; -import org.apache.cayenne.modeler.event.model.ObjEntityEvent; -import org.apache.cayenne.modeler.event.model.ObjAttributeEvent; -import org.apache.cayenne.modeler.event.model.ObjAttributeListener; -import org.apache.cayenne.modeler.event.model.ObjEntityListener; -import org.apache.cayenne.modeler.event.model.ObjRelationshipListener; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.jgraph.graph.AttributeMap; -import org.jgraph.graph.DefaultEdge; -import org.jgraph.graph.DefaultGraphCell; -import org.jgraph.graph.GraphConstants; - -import java.awt.Color; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -/** - * Builder of ObjEntity information-based graph (relative to UML class diagram) - */ -class ObjGraphBuilder extends BaseGraphBuilder<ObjEntity, ObjAttribute, ObjRelationship> implements ObjEntityListener, - ObjAttributeListener, ObjRelationshipListener { - - static final Color ENTITY_COLOR = new Color(255, 255, 185); - - Map<ObjEntity, DefaultEdge> inheritanceEdges; - - public ObjGraphBuilder() { - inheritanceEdges = new HashMap<>(); - } - - @Override - protected Collection<ObjEntity> getEntities(DataMap map) { - return map.getObjEntities(); - } - - @Override - protected boolean isIsolated(DataChannelDescriptor domain, ObjEntity entity) { - - if (!super.isIsolated(domain, entity)) { - return false; - } - - if (entity.getSuperEntity() != null) { - return false; - } - - // TODO: andrus 05/30/2010 - reindexing all DataMaps every time may be VERY slow on large projects - EntityResolver resolver = new EntityResolver(domain.getDataMaps()); - EntityInheritanceTree inheritanceTree = resolver.getInheritanceTree(entity.getName()); - return inheritanceTree == null || inheritanceTree.getChildren().isEmpty(); - } - - @Override - protected void postProcessEntity(ObjEntity entity, DefaultGraphCell cell) { - super.postProcessEntity(entity, cell); - - GraphConstants.setBackground(cell.getAttributes(), ENTITY_COLOR); - GraphConstants.setOpaque(cell.getAttributes(), true); - - DefaultEdge edge = createInheritanceEdge(entity); - if (edge != null) { - createdObjects.add(edge); - } - } - - DefaultEdge createInheritanceEdge(ObjEntity entity) { - if (!inheritanceEdges.containsKey(entity)) { - ObjEntity superEntity = entity.getSuperEntity(); - if (superEntity != null) { - DefaultGraphCell sourceCell = entityCells.get(entity.getName()); - DefaultGraphCell targetCell = entityCells.get(superEntity.getName()); - - DefaultEdge edge = new DefaultEdge(); - edge.setSource(sourceCell.getChildAt(0)); - edge.setTarget(targetCell.getChildAt(0)); - - GraphConstants.setDashPattern(edge.getAttributes(), new float[] {5, 5}); - GraphConstants.setLineEnd(edge.getAttributes(), GraphConstants.ARROW_TECHNICAL); - GraphConstants.setSelectable(edge.getAttributes(), false); - - inheritanceEdges.put(entity, edge); - - return edge; - } - } - return null; - } - - @Override - protected ObjEntityCellMetadata getCellMetadata(ObjEntity e) { - return new ObjEntityCellMetadata(this, e); - } - - @Override - public void setProjectSession(ProjectSession session) { - super.setProjectSession(session); - - session.addObjEntityListener(this); - session.addObjAttributeListener(this); - session.addObjRelationshipListener(this); - } - - public void destroy() { - super.destroy(); - - session.removeObjEntityListener(this); - session.removeObjAttributeListener(this); - session.removeObjRelationshipListener(this); - } - - public void objEntityAdded(ObjEntityEvent e) { - insertEntityCell((ObjEntity) e.getEntity()); - } - - public void objEntityChanged(ObjEntityEvent e) { - remapEntity(e); - - updateEntityCell((ObjEntity)e.getEntity()); - - // maybe super entity was changed - ObjEntity entity = (ObjEntity) e.getEntity(); - DefaultEdge inheritanceEdge = inheritanceEdges.get(entity); - if (inheritanceEdge != null) { - if (entity.getSuperEntity() == null) { - graph.getGraphLayoutCache().remove(new Object[] {inheritanceEdge}); - inheritanceEdges.remove(entity); - } - else { - inheritanceEdge.setTarget(entityCells.get(entity.getSuperEntity().getName()).getChildAt(0)); - - Map<DefaultEdge, AttributeMap> nested = new HashMap<>(); - nested.put(inheritanceEdge, inheritanceEdge.getAttributes()); - - graph.getGraphLayoutCache().edit(nested); - } - } - else { - if (entity.getSuperEntity() != null) { - DefaultEdge edge = createInheritanceEdge(entity); - graph.getGraphLayoutCache().insert(edge); - } - } - } - - public void objEntityRemoved(ObjEntityEvent e) { - removeEntityCell((ObjEntity)e.getEntity()); - } - - public void objAttributeAdded(ObjAttributeEvent e) { - updateEntityCell((ObjEntity)e.getEntity()); - } - - public void objAttributeChanged(ObjAttributeEvent e) { - updateEntityCell((ObjEntity)e.getEntity()); - } - - public void objAttributeRemoved(ObjAttributeEvent e) { - updateEntityCell((ObjEntity)e.getEntity()); - } - - public void objRelationshipAdded(ObjRelationshipEvent e) { - // nothing because relationship does not have target yet - } - - public void objRelationshipChanged(ObjRelationshipEvent e) { - remapRelationship(e.getRelationship(), e, e.getEntity().getName()); - updateRelationshipCell(e.getRelationship()); - } - - public void objRelationshipRemoved(ObjRelationshipEvent e) { - removeRelationshipCell((ObjRelationship)e.getRelationship()); - } - - @Override - protected void removeEntityCell(ObjEntity e) { - super.removeEntityCell(e); - inheritanceEdges.remove(e); - } - - public GraphType getType() { - return GraphType.CLASS; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/action/GlobalActions.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/action/GlobalActions.java index d3e0cb4fb..e06abe70a 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/action/GlobalActions.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/action/GlobalActions.java @@ -24,7 +24,6 @@ import org.apache.cayenne.di.Inject; import org.apache.cayenne.modeler.Application; import org.apache.cayenne.modeler.toolkit.AppAction; import org.apache.cayenne.modeler.ui.action.*; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.ShowGraphEntityAction; import org.apache.cayenne.project.ConfigurationNodeParentGetter; import javax.swing.*; @@ -118,8 +117,7 @@ public class GlobalActions { CreateAttributeAction.class.getName(), CreateRelationshipAction.class.getName(), ObjEntityCounterpartAction.class.getName(), - ObjEntityToSuperEntityAction.class.getName(), - ShowGraphEntityAction.class.getName())); + ObjEntityToSuperEntityAction.class.getName())); dbEntityActions = new HashSet<>(dataMapActions); @@ -128,7 +126,6 @@ public class GlobalActions { CreateRelationshipAction.class.getName(), DbEntitySyncAction.class.getName(), DbEntityCounterpartAction.class.getName(), - ShowGraphEntityAction.class.getName(), CreateObjEntityFromDbAction.class.getName())); embeddableActions = new HashSet<>(dataMapActions); @@ -220,7 +217,6 @@ public class GlobalActions { registerAction(redoAction); registerAction(new CreateEmbeddableAction(application)); - registerAction(new ShowGraphEntityAction(application)); registerAction(new CollapseTreeAction(application)); registerAction(new FilterAction(application)); diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/EntityHandler.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/EntityHandler.java deleted file mode 100644 index e51646a5e..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/EntityHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ - -package org.apache.cayenne.modeler.service.graph; - -import java.awt.geom.Rectangle2D; -import java.util.Hashtable; -import java.util.Map; - -import org.apache.cayenne.configuration.xml.NamespaceAwareNestedTagHandler; -import org.jgraph.graph.GraphConstants; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -class EntityHandler extends NamespaceAwareNestedTagHandler { - - static final String ENTITY_TAG = "entity"; - - GraphHandler graphHandler; - - public EntityHandler(GraphHandler parentHandler) { - super(parentHandler); - this.graphHandler = parentHandler; - } - - @Override - protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException { - switch (localName) { - case ENTITY_TAG: - String name = attributes.getValue("name"); - Map<String, Object> props = new Hashtable<>(); - GraphConstants.setBounds(props, - new Rectangle2D.Double( - Double.valueOf(attributes.getValue("x")), - Double.valueOf(attributes.getValue("y")), - Double.valueOf(attributes.getValue("width")), - Double.valueOf(attributes.getValue("height")) - )); - graphHandler.propertiesMap.put(name, props); - return true; - } - return false; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphExtension.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphExtension.java deleted file mode 100644 index a24be2202..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphExtension.java +++ /dev/null @@ -1,71 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ - -package org.apache.cayenne.modeler.service.graph; - -import org.apache.cayenne.configuration.ConfigurationNodeVisitor; -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.configuration.xml.DataChannelMetaData; -import org.apache.cayenne.di.Inject; -import org.apache.cayenne.di.Provider; -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.graph.GraphRegistry; -import org.apache.cayenne.project.Project; -import org.apache.cayenne.project.extension.BaseNamingDelegate; -import org.apache.cayenne.project.extension.LoaderDelegate; -import org.apache.cayenne.project.extension.ProjectExtension; -import org.apache.cayenne.project.extension.SaverDelegate; - -public class GraphExtension implements ProjectExtension { - - static final String NAMESPACE = "http://cayenne.apache.org/schema/" + Project.VERSION + "/graph"; - - static final String GRAPH_SUFFIX = ".graph.xml"; - - @Inject - protected Provider<DataChannelMetaData> metaDataProvider; - - @Inject - protected Provider<Application> applicationProvider; - - @Override - public LoaderDelegate createLoaderDelegate() { - return new GraphLoaderDelegate(applicationProvider.get(), metaDataProvider.get()); - } - - @Override - public SaverDelegate createSaverDelegate() { - return new GraphSaverDelegate(metaDataProvider.get()); - } - - @Override - public ConfigurationNodeVisitor<String> createNamingDelegate() { - return new BaseNamingDelegate() { - @Override - public String visitDataChannelDescriptor(DataChannelDescriptor channelDescriptor) { - // if there is no registry, than there is no need to save anything - GraphRegistry registry = metaDataProvider.get().get(channelDescriptor, GraphRegistry.class); - if (registry == null) { - return null; - } - return channelDescriptor.getName() + GRAPH_SUFFIX; - } - }; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphHandler.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphHandler.java deleted file mode 100644 index d71abc5fc..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphHandler.java +++ /dev/null @@ -1,94 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.service.graph; - -import org.apache.cayenne.configuration.xml.DataChannelMetaData; -import org.apache.cayenne.configuration.xml.NamespaceAwareNestedTagHandler; -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.graph.GraphMap; -import org.apache.cayenne.modeler.graph.GraphRegistry; -import org.apache.cayenne.modeler.graph.GraphType; -import org.apache.cayenne.util.Util; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; - -import java.util.HashMap; -import java.util.Map; - -/** - * Class to load graph from XML - */ -class GraphHandler extends NamespaceAwareNestedTagHandler { - - static final String GRAPH_TAG = "graph"; - - static final String ENTITY_TAG = "entity"; - - Map<String, Map<String, ?>> propertiesMap; - - GraphType graphType; - - double scale; - - public GraphHandler(NamespaceAwareNestedTagHandler parent, Application application, DataChannelMetaData metaData) { - super(parent); - // Park parsed graph state in metaData. The live GraphBuilder (which subscribes - // to model events) is created later, when the user opens the Graph tab — by - // then the project lifecycle has reached the "open" state and the event bus - // is wired up. - loaderContext.addDataChannelListener(dataChannelDescriptor -> { - GraphRegistry registry = metaData.get(dataChannelDescriptor, GraphRegistry.class); - if (registry == null) { - registry = new GraphRegistry(); - metaData.add(dataChannelDescriptor, registry); - } - - GraphMap map = registry.getGraphMap(dataChannelDescriptor); - map.parkParsedState(graphType, scale, propertiesMap); - }); - } - - @Override - protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException { - switch (localName) { - case GRAPH_TAG: - String type = attributes.getValue("type"); - if (Util.isEmptyString(type)) { - throw new SAXException("Graph type not specified"); - } - - graphType = GraphType.valueOf(type); - scale = Double.parseDouble(attributes.getValue("scale")); - propertiesMap = new HashMap<>(); - return true; - } - - return false; - } - - @Override - protected ContentHandler createChildTagHandler(String namespaceURI, String localName, String qName, Attributes attributes) { - switch (localName) { - case ENTITY_TAG: - return new EntityHandler(this); - } - return super.createChildTagHandler(namespaceURI, localName, qName, attributes); - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphLoaderDelegate.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphLoaderDelegate.java deleted file mode 100644 index 7fc9ba1d3..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphLoaderDelegate.java +++ /dev/null @@ -1,49 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ - -package org.apache.cayenne.modeler.service.graph; - -import org.apache.cayenne.configuration.xml.DataChannelMetaData; -import org.apache.cayenne.configuration.xml.NamespaceAwareNestedTagHandler; -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.project.extension.LoaderDelegate; - -class GraphLoaderDelegate implements LoaderDelegate { - - private final Application application; - private final DataChannelMetaData metaData; - - GraphLoaderDelegate(Application application, DataChannelMetaData metaData) { - this.application = application; - this.metaData = metaData; - } - - @Override - public String getTargetNamespace() { - return GraphExtension.NAMESPACE; - } - - @Override - public NamespaceAwareNestedTagHandler createHandler(NamespaceAwareNestedTagHandler parent, String tag) { - if(GraphsRootHandler.GRAPHS_TAG.equals(tag)) { - return new GraphsRootHandler(parent, application, metaData); - } - return null; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphSaverDelegate.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphSaverDelegate.java deleted file mode 100644 index 960642ef2..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphSaverDelegate.java +++ /dev/null @@ -1,69 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ - -package org.apache.cayenne.modeler.service.graph; - -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.configuration.xml.DataChannelMetaData; -import org.apache.cayenne.modeler.graph.GraphMap; -import org.apache.cayenne.modeler.graph.GraphRegistry; -import org.apache.cayenne.project.extension.BaseSaverDelegate; - -class GraphSaverDelegate extends BaseSaverDelegate { - - DataChannelMetaData metaData; - - GraphSaverDelegate(DataChannelMetaData metaData) { - this.metaData = metaData; - } - - @Override - public Void visitDataChannelDescriptor(DataChannelDescriptor channelDescriptor) { - GraphRegistry registry = metaData.get(channelDescriptor, GraphRegistry.class); - if (registry == null) { - return null; - } - - if(isStandalone()) { - printGraphs(channelDescriptor); - } else { - printInclude(channelDescriptor); - } - - return null; - } - - private void printGraphs(DataChannelDescriptor channelDescriptor) { - GraphRegistry registry = metaData.get(channelDescriptor, GraphRegistry.class); - GraphMap map = registry.getGraphMap(channelDescriptor); - encoder.start("graphs") - .attribute("xmlns", GraphExtension.NAMESPACE) - .nested(map, getParentDelegate()) - .end(); - } - - private void printInclude(DataChannelDescriptor channelDescriptor) { - encoder.start("xi:include") - .attribute("xmlns:xi", "http://www.w3.org/2001/XInclude") - .attribute("href", channelDescriptor.getName() + GraphExtension.GRAPH_SUFFIX) - .end(); - } - - -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphsRootHandler.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphsRootHandler.java deleted file mode 100644 index 5ddb8f725..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/service/graph/GraphsRootHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ - -package org.apache.cayenne.modeler.service.graph; - -import org.apache.cayenne.configuration.xml.DataChannelMetaData; -import org.apache.cayenne.configuration.xml.NamespaceAwareNestedTagHandler; -import org.apache.cayenne.modeler.Application; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; - -class GraphsRootHandler extends NamespaceAwareNestedTagHandler { - - static final String GRAPHS_TAG = "graphs"; - - private final Application application; - private final DataChannelMetaData metaData; - - public GraphsRootHandler(NamespaceAwareNestedTagHandler parentHandler, Application application, DataChannelMetaData metaData) { - super(parentHandler); - setTargetNamespace(GraphExtension.NAMESPACE); - this.application = application; - this.metaData = metaData; - } - - @Override - protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException { - return GRAPHS_TAG.equals(localName); - } - - @Override - protected ContentHandler createChildTagHandler(String namespaceURI, String localName, String qName, Attributes attributes) { - if(GraphHandler.GRAPH_TAG.equals(localName)) { - return new GraphHandler(this, application, metaData); - } - return super.createChildTagHandler(namespaceURI, localName, qName, attributes); - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/DataDomainView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/DataDomainView.java index 4cc349487..9df940669 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/DataDomainView.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/DataDomainView.java @@ -26,8 +26,6 @@ import org.apache.cayenne.modeler.ui.action.ShowValidationConfigAction; import org.apache.cayenne.modeler.project.ProjectSession; import org.apache.cayenne.modeler.ui.project.editor.datadomain.cgen.DataDomainCgenTab; import org.apache.cayenne.modeler.ui.project.editor.datadomain.dbimport.DataDomainDbImportTab; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.DataDomainGraphTab; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.ShowGraphEntityAction; import org.apache.cayenne.modeler.ui.project.editor.datadomain.main.DataDomainMainView; import org.apache.cayenne.modeler.ui.project.editor.datadomain.validation.ValidationTab; @@ -36,7 +34,6 @@ import javax.swing.event.ChangeEvent; public class DataDomainView extends ProjectTabbedPane { - private final DataDomainGraphTab graphTab; private final JComponent cgenView; private final DataDomainCgenTab cgenTab; private final JComponent dbImportView; @@ -49,7 +46,6 @@ public class DataDomainView extends ProjectTabbedPane { this.dbImportView = new JScrollPane(dbImportTab); this.cgenTab = new DataDomainCgenTab(session); this.cgenView = new JScrollPane(cgenTab); - this.graphTab = new DataDomainGraphTab(session); this.validationTab = new ValidationTab(session); initLayout(); initBindings(); @@ -60,7 +56,6 @@ public class DataDomainView extends ProjectTabbedPane { addTab("Main", new JScrollPane(new DataDomainMainView(session))); addTab("Db Import", dbImportView); addTab("Class Generation", cgenView); - addTab("Graph", graphTab); addTab("Validation", validationTab); } @@ -72,21 +67,13 @@ public class DataDomainView extends ProjectTabbedPane { } private void onEntitySelected(ObjEntityDisplayEvent e) { - if (e.getSource() instanceof ShowGraphEntityAction) { - setSelectedComponent(graphTab); - } } private void onEntitySelected(DbEntityDisplayEvent e) { - if (e.getSource() instanceof ShowGraphEntityAction) { - setSelectedComponent(graphTab); - } } private void stateChanged(ChangeEvent e) { - if (getSelectedComponent() == graphTab) { - graphTab.refresh(); - } else if (getSelectedComponent() == cgenView) { + if (getSelectedComponent() == cgenView) { cgenTab.initView(); } else if (getSelectedComponent() == dbImportView) { dbImportTab.initView(); diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/DataDomainGraphTab.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/DataDomainGraphTab.java deleted file mode 100644 index ead40ec4b..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/DataDomainGraphTab.java +++ /dev/null @@ -1,196 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph; - -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.map.Entity; -import org.apache.cayenne.map.ObjEntity; -import org.apache.cayenne.modeler.event.display.DbEntityDisplayEvent; -import org.apache.cayenne.modeler.event.display.DomainDisplayEvent; -import org.apache.cayenne.modeler.event.display.DomainDisplayListener; -import org.apache.cayenne.modeler.event.display.ObjEntityDisplayEvent; -import org.apache.cayenne.modeler.graph.GraphBuilder; -import org.apache.cayenne.modeler.graph.GraphRegistry; -import org.apache.cayenne.modeler.graph.GraphType; -import org.apache.cayenne.modeler.toolkit.combobox.CMComboBox; -import org.apache.cayenne.modeler.toolkit.ProjectPanel; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.RebuildGraphAction; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.SaveAsImageAction; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.ShowGraphEntityAction; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.ZoomInAction; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.ZoomOutAction; -import org.jgraph.JGraph; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -/** - * Tab for editing graphical representation of a dataDomain - */ -public class DataDomainGraphTab extends ProjectPanel implements DomainDisplayListener, ItemListener { - - JComboBox<String> diagramCombo; - JScrollPane scrollPane; - JGraph graph; - DataChannelDescriptor domain; - boolean needRebuild; - GraphRegistry graphRegistry; - - public DataDomainGraphTab(ProjectSession session) { - super(session); - - needRebuild = true; - session.addDomainDisplayListener(this); - session.addObjEntityDisplayListener(this::entityFocused); - session.addDbEntityDisplayListener(this::entityFocused); - - setLayout(new BorderLayout()); - JToolBar toolbar = new JToolBar(); - toolbar.setFloatable(false); - toolbar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); - - GraphType[] types = GraphType.values(); - String[] names = new String[types.length]; - for (int i = 0; i < types.length; i++) { - names[i] = types[i].getName(); - } - - diagramCombo = new CMComboBox<>(names); - diagramCombo.addItemListener(this); - - toolbar.add(new RebuildGraphAction(this,app).buildButton(1)); - toolbar.add(new SaveAsImageAction(this, app).buildButton(3)); - toolbar.addSeparator(); - toolbar.add(new ZoomInAction(this, app).buildButton(1)); - toolbar.add(new ZoomOutAction(this, app).buildButton(3)); - - toolbar.addSeparator(); - toolbar.add(new JLabel("Diagram: ")); - toolbar.add(diagramCombo); - add(toolbar, BorderLayout.NORTH); - - scrollPane = new JScrollPane(); - add(scrollPane); - } - - public void domainSelected(DomainDisplayEvent e) { - if (domain != e.getDomain()) { - needRebuild = true; - domain = e.getDomain(); - - if (isVisible()) { - refresh(); - } - } - } - - private void entityFocused(ObjEntityDisplayEvent e) { - if (e.getSource() instanceof ShowGraphEntityAction) { - focusEntity(e.getEntity(), e.getDomain()); - } - } - - private void entityFocused(DbEntityDisplayEvent e) { - if (e.getSource() instanceof ShowGraphEntityAction) { - focusEntity(e.getEntity(), e.getDomain()); - } - } - - private void focusEntity(Entity<?, ?, ?> entity, DataChannelDescriptor entityDomain) { - if (entity == null) { - return; - } - - // align graph domain to selection if needed - if (domain != entityDomain) { - domain = entityDomain; - needRebuild = true; - } - - // choose type of diagram - diagramCombo.setSelectedIndex(entity instanceof ObjEntity ? 1 : 0); - refresh(); - - GraphBuilder builder = getGraphRegistry().getGraphMap(domain).get(getSelectedType()); - - Object cell = builder.getEntityCell(entity.getName()); - - if (cell != null) { - graph.setSelectionCell(cell); - graph.scrollCellToVisible(cell); - } - } - - /** - * Rebuilds graph from a domain, if it is not yet built Otherwise, takes it - * from cache - */ - public void refresh() { - if (needRebuild && domain != null) { - graph = getGraphRegistry().loadGraph(session, domain, getSelectedType()); - scrollPane.setViewportView(graph); - - needRebuild = false; - } - } - - private GraphType getSelectedType() { - return GraphType.values()[diagramCombo.getSelectedIndex()]; - } - - /** - * Rebuilds graph, deleting existing if needed - */ - public void rebuild() { - if (domain != null) { - JOptionPane pane = new JOptionPane("Rebuilding graph from domain will cause all user" - + " changes to be lost. Continue?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); - - JDialog dialog = pane.createDialog(app.getFrame(), "Confirm Rebuild"); - dialog.setVisible(true); - - if (pane.getValue().equals(JOptionPane.YES_OPTION)) { - getGraphRegistry().getGraphMap(domain).remove(getSelectedType()); - itemStateChanged(null); - } - } - } - - public void itemStateChanged(ItemEvent e) { - needRebuild = true; - refresh(); - } - - public JGraph getGraph() { - return graph; - } - - GraphRegistry getGraphRegistry() { - graphRegistry = app.getMetaData().get(domain, GraphRegistry.class); - if (graphRegistry == null) { - graphRegistry = new GraphRegistry(); - app.getMetaData().add(domain, graphRegistry); - } - - return graphRegistry; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/EntityDisplayAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/EntityDisplayAction.java deleted file mode 100644 index f8b840bd1..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/EntityDisplayAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action; - -import org.apache.cayenne.configuration.ConfigurationNode; -import org.apache.cayenne.map.Entity; -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.graph.GraphBuilder; -import org.apache.cayenne.modeler.ui.action.FindAction; -import org.apache.cayenne.modeler.toolkit.AppAction; - -import javax.swing.*; -import java.awt.event.ActionEvent; - -/** - * Action that displays one of the objects in main tree, and then fires another action (if specified) - */ -public class EntityDisplayAction extends AppAction { - - /** - * Action that will be performed after selection - */ - private AppAction delegate; - - private final GraphBuilder builder; - - public EntityDisplayAction(GraphBuilder builder, Application application) { - super(application, "Show"); - this.builder = builder; - init(); - } - - public EntityDisplayAction(GraphBuilder builder, AppAction delegate, Application application) { - super(application, (String) delegate.getValue(Action.NAME)); - this.delegate = delegate; - this.builder = builder; - init(); - } - - private void init() { - setEnabled(true); - - // Create icon manually, because at creation of super object delegate is null - Icon icon = createIcon(); - if (icon != null) { - super.putValue(Action.SMALL_ICON, icon); - } - } - - @Override - public void performAction(ActionEvent e) { - if (display()) { - if (delegate != null) { - delegate.performAction(e); - } - } - } - - private boolean display() { - Entity<?,?,?> entity = builder.getSelectedEntity(); - if (entity == null) { - return false; - } - - // reusing logic from FindAction - FindAction.jumpToResult(new FindAction.SearchResultEntry(entity, entity.getName()), app); - return true; - } - - @Override - public String getIconName() { - if (delegate != null) { - return delegate.getIconName(); - } - return null; - } - - @Override - public boolean enableForPath(ConfigurationNode object) { - return builder.getSelectedEntity() != null; - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/RebuildGraphAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/RebuildGraphAction.java deleted file mode 100644 index 7b75abd02..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/RebuildGraphAction.java +++ /dev/null @@ -1,48 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action; - -import java.awt.event.ActionEvent; - -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.DataDomainGraphTab; -import org.apache.cayenne.modeler.toolkit.AppAction; - -/** - * Action for refreshing the graph - */ -public class RebuildGraphAction extends AppAction { - private final DataDomainGraphTab dataDomainGraphTab; - - public RebuildGraphAction(DataDomainGraphTab dataDomainGraphTab, Application application) { - super(application, "Rebuild"); - this.dataDomainGraphTab = dataDomainGraphTab; - setEnabled(true); - } - - @Override - public String getIconName() { - return "icon-refresh.png"; - } - - @Override - public void performAction(ActionEvent e) { - this.dataDomainGraphTab.rebuild(); - } -} \ No newline at end of file diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/RemoveEntityAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/RemoveEntityAction.java deleted file mode 100644 index 827a1bdc5..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/RemoveEntityAction.java +++ /dev/null @@ -1,67 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action; - -import org.apache.cayenne.map.DbEntity; -import org.apache.cayenne.map.Entity; -import org.apache.cayenne.map.ObjEntity; -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.ui.action.RemoveAction; -import org.apache.cayenne.modeler.ui.confirmremove.ConfirmRemoveDialog; -import org.apache.cayenne.modeler.graph.GraphBuilder; -import org.apache.cayenne.modeler.undo.RemoveUndoableEdit; - -import java.awt.event.ActionEvent; - -/** - * Action for removing entities from the graph - */ -public class RemoveEntityAction extends RemoveAction { - - private final GraphBuilder<?,?,?> builder; - - public RemoveEntityAction(GraphBuilder<?,?,?> builder, Application application) { - super(application); - this.builder = builder; - setEnabled(true); - } - - @Override - public void performAction(ActionEvent e, boolean allowAsking) { - ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking); - - Entity<?,?,?> entity = builder.getSelectedEntity(); - if (entity == null) { - return; - } - - if (entity instanceof ObjEntity) { - if (dialog.shouldDelete("ObjEntity", entity.getName())) { - app.getUndoManager().addEdit(new RemoveUndoableEdit(getProjectSession(), entity.getDataMap(), (ObjEntity) entity)); - removeObjEntity(entity.getDataMap(), (ObjEntity) entity); - } - } - else { - if (dialog.shouldDelete("DbEntity", entity.getName())) { - app.getUndoManager().addEdit(new RemoveUndoableEdit(getProjectSession(), entity.getDataMap(), (DbEntity) entity)); - removeDbEntity(entity.getDataMap(), (DbEntity) entity); - } - } - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/SaveAsImageAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/SaveAsImageAction.java deleted file mode 100644 index 734567309..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/SaveAsImageAction.java +++ /dev/null @@ -1,105 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action; - -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.toolkit.AppAction; -import org.apache.cayenne.modeler.toolkit.filechooser.CMFileChooserPrefs; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.DataDomainGraphTab; -import org.apache.cayenne.modeler.toolkit.filechooser.FileFilters; -import org.jgraph.JGraph; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.imageio.ImageIO; -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Action for saving graph as image - */ -public class SaveAsImageAction extends AppAction { - private static final Logger LOGGER = LoggerFactory.getLogger(SaveAsImageAction.class); - - private final DataDomainGraphTab dataDomainGraphTab; - - public SaveAsImageAction(DataDomainGraphTab dataDomainGraphTab, Application application) { - super(application, "Save As Image"); - this.dataDomainGraphTab = dataDomainGraphTab; - setEnabled(true); - } - - @Override - public String getIconName() { - return "icon-save-as-image.png"; - } - - @Override - public void performAction(ActionEvent e) { - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - - new CMFileChooserPrefs(app.getPreferencesRepository(), "saveAsImage/lastDir").bind(chooser); - - chooser.setAcceptAllFileFilterUsed(false); - - String ext = "png"; - chooser.addChoosableFileFilter(FileFilters.getExtensionFileFilter(ext, "PNG Images")); - - int status = chooser.showSaveDialog(app.getFrame()); - if (status == JFileChooser.APPROVE_OPTION) { - String path = chooser.getSelectedFile().getPath(); - if (!path.endsWith("." + ext)) { - path += "." + ext; - } - - File file = new File(path); - - try { - JGraph graph = dataDomainGraphTab.getGraph(); - BufferedImage img = graph.getImage(null, 0); - - if (file.exists()) { - int response = JOptionPane.showConfirmDialog(null, - "Do you want to replace the existing file?", - "Confirm", JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); - if (response != JOptionPane.YES_OPTION) { - return; - } - } - - try (OutputStream out = new FileOutputStream(file)) { - ImageIO.write(img, ext, out); - out.flush(); - } - - } catch (IOException ex) { - LOGGER.error("Could not save image", ex); - JOptionPane.showMessageDialog(app.getFrame(), "Could not save image.", "Error saving image", - JOptionPane.ERROR_MESSAGE); - } - } - } -} \ No newline at end of file diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ShowGraphEntityAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ShowGraphEntityAction.java deleted file mode 100644 index 67f0b5188..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ShowGraphEntityAction.java +++ /dev/null @@ -1,93 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action; - -import java.awt.event.ActionEvent; - -import org.apache.cayenne.configuration.ConfigurationNode; -import org.apache.cayenne.configuration.DataChannelDescriptor; -import org.apache.cayenne.map.DbEntity; -import org.apache.cayenne.map.Entity; -import org.apache.cayenne.map.ObjEntity; -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.event.display.DbEntityDisplayEvent; -import org.apache.cayenne.modeler.event.display.ObjEntityDisplayEvent; -import org.apache.cayenne.modeler.toolkit.AppAction; -import org.apache.cayenne.modeler.project.ProjectSession; -import org.apache.cayenne.modeler.ui.project.ProjectView; - -/** - * Action that shows entity on the graph - */ -public class ShowGraphEntityAction extends AppAction { - - public static String getActionName() { - return "ShowGraphEntity"; - } - - public ShowGraphEntityAction(Application application) { - super(application, getActionName(), "Show on Graph"); - setEnabled(true); - } - - @Override - public String getIconName() { - return "icon-save-as-image.png"; - } - - @Override - public void performAction(ActionEvent e) { - Entity<?,?,?> entity = null; - - ProjectSession session = getProjectSession(); - if (session.getSelectedDbEntity() != null) { - entity = session.getSelectedDbEntity(); - } else if (session.getSelectedObjEntity() != null) { - entity = session.getSelectedObjEntity(); - } - - if (entity != null) { - showEntity(entity); - } - } - - @Override - public boolean enableForPath(ConfigurationNode object) { - return object instanceof Entity; - } - - void showEntity(Entity<?,?,?> entity) { - // we're always in same domain - ProjectView editor = app.getFrame().getProjectView(); - - editor.getProjectTreeView().getSelectionModel().setSelectionPath( - editor - .getProjectTreeView() - .getSelectionPath() - .getParentPath() - .getParentPath()); - - DataChannelDescriptor domain = (DataChannelDescriptor) getProjectSession().project().getRootNode(); - if (entity instanceof ObjEntity) { - getProjectSession().displayObjEntity(new ObjEntityDisplayEvent(this, domain, entity.getDataMap(), (ObjEntity) entity)); - } else if (entity instanceof DbEntity) { - getProjectSession().displayDbEntity(new DbEntityDisplayEvent(this, domain, entity.getDataMap(), (DbEntity) entity)); - } - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ZoomInAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ZoomInAction.java deleted file mode 100644 index f26ff9b65..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ZoomInAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action; - -import java.awt.event.ActionEvent; - -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.DataDomainGraphTab; -import org.apache.cayenne.modeler.graph.GraphBuilder; -import org.apache.cayenne.modeler.toolkit.AppAction; -import org.jgraph.JGraph; - -/** - * Action for zooming in graph - */ -public class ZoomInAction extends AppAction { - private final DataDomainGraphTab dataDomainGraphTab; - - public ZoomInAction(DataDomainGraphTab dataDomainGraphTab, Application application) { - super(application, "Zoom In"); - this.dataDomainGraphTab = dataDomainGraphTab; - setEnabled(true); - } - - @Override - public String getIconName() { - return "icon-zoom-in.png"; - } - - @Override - public void performAction(ActionEvent e) { - JGraph graph = dataDomainGraphTab.getGraph(); - graph.setScale(graph.getScale() * GraphBuilder.ZOOM_FACTOR); - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ZoomOutAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ZoomOutAction.java deleted file mode 100644 index 3d547f5ad..000000000 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datadomain/graph/action/ZoomOutAction.java +++ /dev/null @@ -1,51 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action; - -import java.awt.event.ActionEvent; - -import org.apache.cayenne.modeler.Application; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.DataDomainGraphTab; -import org.apache.cayenne.modeler.graph.GraphBuilder; -import org.apache.cayenne.modeler.toolkit.AppAction; -import org.jgraph.JGraph; - -/** - * Action for zooming out graph - */ -public class ZoomOutAction extends AppAction { - private final DataDomainGraphTab dataDomainGraphTab; - - public ZoomOutAction(DataDomainGraphTab dataDomainGraphTab, Application application) { - super(application, "Zoom Out"); - this.dataDomainGraphTab = dataDomainGraphTab; - setEnabled(true); - } - - @Override - public String getIconName() { - return "icon-zoom-out.png"; - } - - @Override - public void performAction(ActionEvent e) { - JGraph graph = dataDomainGraphTab.getGraph(); - graph.setScale(graph.getScale() / GraphBuilder.ZOOM_FACTOR); - } -} diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/dbentity/main/DbEntityMainView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/dbentity/main/DbEntityMainView.java index 12d35ebca..e522ca5ec 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/dbentity/main/DbEntityMainView.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/dbentity/main/DbEntityMainView.java @@ -37,7 +37,6 @@ import org.apache.cayenne.modeler.ui.action.DbEntityCounterpartAction; import org.apache.cayenne.modeler.ui.action.DbEntitySyncAction; import org.apache.cayenne.modeler.project.ProjectSession; import org.apache.cayenne.modeler.ui.project.editor.ExpressionConvertor; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.ShowGraphEntityAction; import org.apache.cayenne.modeler.ui.project.editor.query.ExistingSelectionProcessor; import org.apache.cayenne.project.extension.info.ObjectInfo; import org.apache.cayenne.util.Util; @@ -103,8 +102,6 @@ public class DbEntityMainView extends ProjectPanel implements ExistingSelectionP toolBar.add(globalActions.getAction(CreateObjEntityFromDbAction.class).buildButton(1)); toolBar.add(globalActions.getAction(DbEntitySyncAction.class).buildButton(2)); toolBar.add(globalActions.getAction(DbEntityCounterpartAction.class).buildButton(3)); - toolBar.addSeparator(); - toolBar.add(globalActions.getAction(ShowGraphEntityAction.class).buildButton()); pkGeneratorType.setEditable(false); pkGeneratorType.setModel(new DefaultComboBoxModel<>(PK_GENERATOR_TYPES)); diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/main/ObjEntityMainView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/main/ObjEntityMainView.java index a658b3920..de2c43a17 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/main/ObjEntityMainView.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/main/ObjEntityMainView.java @@ -44,7 +44,6 @@ import org.apache.cayenne.modeler.toolkit.text.CMUndoableTextField; import org.apache.cayenne.modeler.toolkit.ProjectPanel; import org.apache.cayenne.modeler.project.ProjectSession; import org.apache.cayenne.modeler.ui.project.editor.ExpressionConvertor; -import org.apache.cayenne.modeler.ui.project.editor.datadomain.graph.action.ShowGraphEntityAction; import org.apache.cayenne.modeler.ui.project.editor.objentity.classname.ClassNameUpdaterController; import org.apache.cayenne.modeler.ui.project.editor.objentity.duplicates.DuplicatedAttributesDialog; import org.apache.cayenne.modeler.ui.project.editor.query.ExistingSelectionProcessor; @@ -109,8 +108,6 @@ public class ObjEntityMainView extends ProjectPanel implements ObjEntityDisplayL toolBar.addSeparator(); toolBar.add(globalActions.getAction(ObjEntitySyncAction.class).buildButton(1)); toolBar.add(globalActions.getAction(ObjEntityCounterpartAction.class).buildButton(3)); - toolBar.addSeparator(); - toolBar.add(globalActions.getAction(ShowGraphEntityAction.class).buildButton()); add(toolBar, BorderLayout.NORTH); tableLabel.setBorderPainted(false); diff --git a/pom.xml b/pom.xml index 706203c79..48d183518 100644 --- a/pom.xml +++ b/pom.xml @@ -375,11 +375,6 @@ <artifactId>commons-beanutils</artifactId> <version>1.11.0</version> </dependency> - <dependency> - <groupId>jgraph</groupId> - <artifactId>jgraph</artifactId> - <version>5.13.0.0</version> - </dependency> <dependency> <groupId>net.java.dev.inflector</groupId> <artifactId>inflector</artifactId>
