Search in sources :

Example 1 with UniqueKey

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

the class XSDElement method setKeys.

/**
 * Use an entity node to set the keys, including foreign keyrefs and
 * uniques.
 * <p/>
 * Key is set from the primary key. KeyRefs are set from the outgoing edges.
 * Uniques are set by Uniques and by noninclusion injective outgoing edges.
 *
 * @param node
 *            we are working with
 */
@SuppressWarnings("unused")
public void setKeys(final EntityNode node) {
    final List<UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> uniqueKeyList = node.getUniqueKeys();
    final XSDComplexType myType = (XSDComplexType) getElementType();
    constraints = new ArrayList<XSDAbstractKey>(uniqueKeyList.size() + 3);
    final String idName = Easik.getInstance().getSettings().getProperty("xml_id_name");
    final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
    final boolean idIsAttribute = Boolean.valueOf(Easik.getInstance().getSettings().getProperty("xml_id_is_attribute"));
    final XSDKey primaryKey = node.createXMLPrimaryKey(this);
    final XSDElement theParent = (XSDElement) getParent();
    theParent.addConstraint(primaryKey);
    for (final SketchEdge edge : node.getOutgoingEdges()) {
        final boolean isInclusion = edge.getTargetEntity().getName().equals(theParent.getName());
        if (edge.isInjective()) {
            if (!isInclusion) {
                constraints.add(new XSDUniqueKey(edge.getForeignKeyName(keyrefName), this, edge.getName()));
            }
        }
        if (!isInclusion) {
            theParent.addConstraint(new XSDKeyRef(this, edge.getTargetEntity().getXMLPrimaryKeyName(), edge.getName()));
            myType.addAtom(new XSDElement(edge.getName(), edge.isPartial(), XSDBaseType.xsInt));
        }
    }
    for (final UniqueKey<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> k : uniqueKeyList) {
        this.addConstraint(new XSDUniqueKey(this, k));
    }
}
Also used : XSDAbstractKey(easik.xml.xsd.nodes.constraints.XSDAbstractKey) XSDKey(easik.xml.xsd.nodes.constraints.XSDKey) XSDKeyRef(easik.xml.xsd.nodes.constraints.XSDKeyRef) SketchGraphModel(easik.sketch.util.graph.SketchGraphModel) EntityNode(easik.sketch.vertex.EntityNode) SketchFrame(easik.ui.SketchFrame) XSDUniqueKey(easik.xml.xsd.nodes.constraints.XSDUniqueKey) SketchEdge(easik.sketch.edge.SketchEdge) XSDUniqueKey(easik.xml.xsd.nodes.constraints.XSDUniqueKey) UniqueKey(easik.model.keys.UniqueKey) Sketch(easik.sketch.Sketch) XSDComplexType(easik.xml.xsd.nodes.types.XSDComplexType)

Example 2 with UniqueKey

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

the class ModelInfoTreeUI method setPopMenuItems.

/**
 * Sets which of the menu items will be visible
 *
 * @return true if the popup should be displayed, false otherwise
 */
public boolean setPopMenuItems() {
    // If there is nothing seleceted then just do nothing
    if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
        return false;
    } else // sketch
    if (_theFrame.getMode() == F.Mode.MANIPULATE) {
        return false;
    }
    // Get currently selected object
    DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
    // Hide all elements
    for (Component c : _popupMenu.getComponents()) {
        c.setVisible(false);
    }
    // Check what is currently selected
    if (curSelected instanceof ModelVertex) {
        _addAttributeItem.setVisible(true);
        _addUniqueKeyItem.setVisible(true);
        _renameEntityItem.setVisible(true);
        _deleteEntityItem.setVisible(true);
    } else if (curSelected instanceof EntityAttribute) {
        if (_theFrame.getMModel() instanceof Sketch) {
            _editAttributeItem.setVisible(true);
            _deleteAttributeItem.setVisible(true);
        }
    } else if (curSelected instanceof UniqueKey) {
        if (_theFrame.getMModel() instanceof Sketch) {
            _editUniqueKeyItem.setVisible(true);
            _deleteUniqueKeyItem.setVisible(true);
        }
    } else if (curSelected instanceof ModelConstraint) {
        if (_theFrame.getMModel() instanceof Sketch) {
            if ((curSelected instanceof SumConstraint) || (curSelected instanceof ProductConstraint) || (curSelected instanceof CommutativeDiagram)) {
                _addPathItem.setVisible(true);
            }
            _deleteConstraintItem.setVisible(true);
        }
    } else if (curSelected instanceof ModelPath) {
        Object myConst = curSelected.getParent();
        if ((myConst instanceof SumConstraint) || (myConst instanceof ProductConstraint) || (myConst instanceof CommutativeDiagram)) {
            _deletePathItem.setVisible(true);
        }
    } else if (curSelected == _tree_entities) {
        _addEntityItem.setVisible(true);
    } else if (curSelected == _tree_constraints) {
        _addCommutativeItem.setVisible(true);
        _addProductItem.setVisible(true);
        _addPullbackItem.setVisible(true);
        _addSumItem.setVisible(true);
    // _addLimItem.setVisible(true);
    } else if (curSelected == _tree_constraints_commutative) {
        _addCommutativeItem.setVisible(true);
    } else if (curSelected == _tree_constraints_product) {
        _addProductItem.setVisible(true);
    } else if (curSelected == _tree_constraints_pullback) {
        _addPullbackItem.setVisible(true);
    } else if (curSelected == _tree_constraints_equalizer) {
        _addEqualizerItem.setVisible(true);
    } else if (curSelected == _tree_constraints_sum) {
        _addSumItem.setVisible(true);
    } else if (curSelected == _tree_constraints_limit) {
    // _addLimItem.setVisible(true);
    } else {
        return false;
    }
    return true;
}
Also used : ProductConstraint(easik.model.constraint.ProductConstraint) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) EntityAttribute(easik.model.attribute.EntityAttribute) ModelConstraint(easik.model.constraint.ModelConstraint) UniqueKey(easik.model.keys.UniqueKey) ModelPath(easik.model.path.ModelPath) ModelVertex(easik.model.vertex.ModelVertex) Sketch(easik.sketch.Sketch) Component(java.awt.Component) SumConstraint(easik.model.constraint.SumConstraint) CommutativeDiagram(easik.model.constraint.CommutativeDiagram)

Example 3 with UniqueKey

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

the class DeleteUniqueKeyAction method actionPerformed.

/**
 * Deletes the currently selected unique key
 *
 * @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()) {
        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();
    // Selection is a unique key
    if (curSelected instanceof UniqueKey) {
        @SuppressWarnings("unchecked") UniqueKey<F, GM, M, N, E> curKey = (UniqueKey<F, GM, M, N, E>) curSelected;
        // cast because we only have uniquekeys in sketches right now so
        // this is not generic
        N parentEntity = curKey.getEntity();
        // Show a confirmation dialog box for the deletion
        if (JOptionPane.showConfirmDialog(_theFrame, "Are you sure you want to delete the '" + curKey.toString() + "' unique key from the '" + parentEntity + "' entity?", "Confirm Delete", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            // Delete the unique key from entity
            parentEntity.removeUniqueKey(curKey);
            // Refresh
            _theFrame.getInfoTreeUI().refreshTree(parentEntity);
            // view
            // of
            // entity
            _theFrame.getMModel().setDirty();
            _theFrame.getMModel().setSynced(false);
        }
    } else // Selection is not an attribute
    {
        JOptionPane.showMessageDialog(_theFrame, "You don't have a unique key selected. \nPlease select a unique key and try again.", "No Attribute Selected", JOptionPane.ERROR_MESSAGE);
        return;
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) UniqueKey(easik.model.keys.UniqueKey)

Example 4 with UniqueKey

use of easik.model.keys.UniqueKey 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)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Sketch (easik.sketch.Sketch)2 EntityAttribute (easik.model.attribute.EntityAttribute)1 CommutativeDiagram (easik.model.constraint.CommutativeDiagram)1 ModelConstraint (easik.model.constraint.ModelConstraint)1 ProductConstraint (easik.model.constraint.ProductConstraint)1 SumConstraint (easik.model.constraint.SumConstraint)1 UniqueKeyUI (easik.model.keys.UniqueKeyUI)1 ModelPath (easik.model.path.ModelPath)1 ModelVertex (easik.model.vertex.ModelVertex)1 SketchEdge (easik.sketch.edge.SketchEdge)1 SketchGraphModel (easik.sketch.util.graph.SketchGraphModel)1 EntityNode (easik.sketch.vertex.EntityNode)1 SketchFrame (easik.ui.SketchFrame)1 XSDAbstractKey (easik.xml.xsd.nodes.constraints.XSDAbstractKey)1 XSDKey (easik.xml.xsd.nodes.constraints.XSDKey)1 XSDKeyRef (easik.xml.xsd.nodes.constraints.XSDKeyRef)1 XSDUniqueKey (easik.xml.xsd.nodes.constraints.XSDUniqueKey)1 XSDComplexType (easik.xml.xsd.nodes.types.XSDComplexType)1