Search in sources :

Example 1 with UniqueKeyUI

use of easik.model.keys.UniqueKeyUI in project fql by CategoricalData.

the class EditUniqueKeyAction method actionPerformed.

/**
 * Brings up a dialog to edit the currently selected unique key
 *
 * @param e
 *            The action event
 */
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
    // If there is nothing seleceted then just do nothing
    if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
        return;
    }
    // cancel operation
    if (_theFrame.getMModel().isSynced()) {
        int choice = JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
        if (choice == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }
    // Get currently selected object
    DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
    N curEntity;
    UniqueKey<F, GM, M, N, E> myKey;
    // Check what is currently selected
    if (curSelected instanceof UniqueKey) {
        // Entity is selected so set it as current entity
        myKey = (UniqueKey<F, GM, M, N, E>) curSelected;
        // we can cast it because we will only edit in sketches
        curEntity = myKey.getEntity();
    } else {
        JOptionPane.showMessageDialog(_theFrame, "You do not have an entity selected. \nPlease select an entity and try again.", "No Entity Selected", JOptionPane.ERROR_MESSAGE);
        // Jump out of function
        return;
    }
    UniqueKeyUI<F, GM, M, N, E> myUI = new UniqueKeyUI<>(_theFrame, curEntity, myKey);
    if (myUI.showDialog()) {
        // Get values from dialog
        myKey.setElements(myUI.getSelectedElements());
        myKey.setKeyName(myUI.getKeyName());
        // Refresh tree
        // Refresh view
        _theFrame.getInfoTreeUI().refreshTree(curSelected);
        // of key
        Object[] myCell = new Object[] { curEntity };
        _theFrame.getMModel().getGraphLayoutCache().hideCells(myCell, true);
        _theFrame.getMModel().getGraphLayoutCache().showCells(myCell, true);
        _theFrame.getMModel().repaint();
        _theFrame.getMModel().setDirty();
        _theFrame.getMModel().setSynced(false);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) UniqueKey(easik.model.keys.UniqueKey) UniqueKeyUI(easik.model.keys.UniqueKeyUI)

Aggregations

UniqueKey (easik.model.keys.UniqueKey)1 UniqueKeyUI (easik.model.keys.UniqueKeyUI)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1