Search in sources :

Example 1 with OverviewVertex

use of easik.overview.vertex.OverviewVertex in project fql by CategoricalData.

the class RenameInOverviewAction method actionPerformed.

/**
 * Called when clicked upon, will rename an article.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theOverview.getSelectionCells();
    if (!((currentSelection.length == 1) && (currentSelection[0] instanceof OverviewVertex))) {
        return;
    }
    OverviewVertex nodeToRename = (OverviewVertex) currentSelection[0];
    String originalName = nodeToRename.getName();
    if (nodeToRename instanceof SketchNode) {
        if (((SketchNode) nodeToRename).getMModel().isSynced() && (JOptionPane.showConfirmDialog(_theOverview.getFrame(), "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION)) {
            return;
        }
    } else if (nodeToRename instanceof ViewNode) {
        if (((ViewNode) nodeToRename).getMModel().getSketch().isSynced() && (JOptionPane.showConfirmDialog(_theOverview.getFrame(), "Warning: this view is of a sketch that is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION)) {
            return;
        }
    } else {
        return;
    }
    String s = (String) JOptionPane.showInputDialog(_theOverview.getParent(), "New name:", "Rename", JOptionPane.QUESTION_MESSAGE, null, null, originalName);
    if (s != null) {
        s = s.trim();
        if (s.equals("")) {
            JOptionPane.showMessageDialog(_theOverview.getParent(), "Sketch name is empty", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (nodeToRename instanceof SketchNode) {
            if (_theOverview.isNameUsed(s) && !nodeToRename.getName().equals(s)) {
                JOptionPane.showMessageDialog(_theOverview.getParent(), "Sketch name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
        } else if (nodeToRename instanceof ViewNode) {
            if (_theOverview.isNameUsed(s) && !nodeToRename.getName().equals(s)) {
                JOptionPane.showMessageDialog(_theOverview.getParent(), "View name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
        if (!s.equals(originalName)) {
            nodeToRename.setName(s);
            _theOverview.getFrame().getInfoTreeUI().storeExpansion();
            _theOverview.getFrame().getInfoTreeUI().refreshTree();
            _theOverview.getGraphLayoutCache().reload();
            _theOverview.getFrame().getInfoTreeUI().revertExpansion();
            if (nodeToRename instanceof SketchNode) {
                ((SketchNode) nodeToRename).getFrame().getMModel().setDirty();
                ((SketchNode) nodeToRename).getFrame().getMModel().setSynced(false);
            } else if (nodeToRename instanceof ViewNode) {
                ((ViewNode) nodeToRename).getFrame().getMModel().setDirty();
                ((ViewNode) nodeToRename).getFrame().getMModel().getSketch().setSynced(false);
            } else {
                _theOverview.setDirty(true);
            }
            _theOverview.repaint();
        }
    }
    _theOverview.clearSelection();
}
Also used : ViewNode(easik.overview.vertex.ViewNode) OverviewVertex(easik.overview.vertex.OverviewVertex) SketchNode(easik.overview.vertex.SketchNode)

Example 2 with OverviewVertex

use of easik.overview.vertex.OverviewVertex in project fql by CategoricalData.

the class RenameInOverviewFromTreeAction method actionPerformed.

/**
 * Called when clicked upon, will rename an article.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    // If there is nothing seleceted then just do nothing
    if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
        System.err.println("'OK'");
        return;
    }
    // Get currently selected object
    DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
    OverviewVertex nodeToRename;
    String originalName = "";
    // Check what is currently selected
    if (curSelected.getUserObject() instanceof SketchNode) {
        nodeToRename = (SketchNode) curSelected.getUserObject();
    } else if (curSelected.getUserObject() instanceof ViewNode) {
        nodeToRename = (ViewNode) curSelected.getUserObject();
    } else {
        return;
    }
    originalName = nodeToRename.getName();
    String s = (String) JOptionPane.showInputDialog(_theFrame, "New name:", "Rename", JOptionPane.QUESTION_MESSAGE, null, null, originalName);
    if (s != null) {
        s = s.trim();
        if (s.equals("")) {
            JOptionPane.showMessageDialog(_theFrame, "Entity name is empty", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (_theFrame.getOverview().isNameUsed(s)) {
            JOptionPane.showMessageDialog(_theFrame, "Entity name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            nodeToRename.setName(s);
            _theFrame.getInfoTreeUI().refreshTree();
            _theFrame.getOverview().getGraphLayoutCache().reload();
            _theFrame.getOverview().repaint();
            if (nodeToRename instanceof SketchNode) {
                ((SketchNode) nodeToRename).getFrame().getMModel().setDirty();
            } else if (nodeToRename instanceof ViewNode) {
                ((ViewNode) nodeToRename).getFrame().getMModel().setDirty();
            }
        }
    }
    _theFrame.getOverview().clearSelection();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ViewNode(easik.overview.vertex.ViewNode) OverviewVertex(easik.overview.vertex.OverviewVertex) SketchNode(easik.overview.vertex.SketchNode)

Aggregations

OverviewVertex (easik.overview.vertex.OverviewVertex)2 SketchNode (easik.overview.vertex.SketchNode)2 ViewNode (easik.overview.vertex.ViewNode)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1