Search in sources :

Example 1 with QueryNode

use of easik.view.vertex.QueryNode in project fql by CategoricalData.

the class ViewFrame method setPopMenu.

/**
 * Figures out which popup menu should be displayed, based on the editing
 * mode of the sketch on which this is a view. Ensures the the appropriate
 * menu items are enabled based on the current selection.
 *
 * @return The popup menu that should be displayed. (i.e. the editing popup
 *         if the sketch of which this view in on is in edit mode and the
 *         manipulate option otherwise.)
 */
public JPopupMenu setPopMenu() {
    Object[] currentSelection = _ourView.getSelectionCells();
    _ViewAddPopItem.setToolTipText("Add a row to the view table refrenced by this query node");
    if (_ourView.getSketch().getFrame().getMode() == SketchFrame.Mode.MANIPULATE) {
        boolean enableViewQuery = currentSelection.length == 1;
        _ViewQueryPopItem.setEnabled(enableViewQuery);
        // Disable all elements
        for (final Component c : _manipModePopMenu.getComponents()) {
            c.setEnabled(false);
        }
        if (currentSelection.length == 0) {
            return null;
        }
        final Object selected = currentSelection[0];
        if (selected instanceof QueryNode) {
            setQueryPopItems((QueryNode) selected);
            return _manipModePopMenu;
        }
        return null;
    }
    // Disable all elements
    for (final Component c : _editModePopMenu.getComponents()) {
        c.setEnabled(false);
    }
    if (currentSelection.length == 0) {
        _AddQueryNodePopItem.setEnabled(true);
        return _editModePopMenu;
    }
    // check for mixed selection
    final Object selected1 = currentSelection[0];
    for (final Object o : currentSelection) {
        if (o.getClass() != selected1.getClass()) {
            // Disable all elements
            for (final Component c : _editModePopMenu.getComponents()) {
                c.setEnabled(false);
            }
            // We always want delete
            _DeletePopItem.setEnabled(true);
            return _editModePopMenu;
        }
    }
    if (selected1 instanceof QueryNode) {
        _DefineQueryNodePopItem.setEnabled(true);
        _DeletePopItem.setEnabled(true);
        return _editModePopMenu;
    } else if (selected1 instanceof View_Edge) {
        return null;
    }
    return null;
}
Also used : QueryNode(easik.view.vertex.QueryNode) Component(java.awt.Component) View_Edge(easik.view.edge.View_Edge)

Example 2 with QueryNode

use of easik.view.vertex.QueryNode in project fql by CategoricalData.

the class ViewUpdateAction method actionPerformed.

/**
 * @param e
 *            The action event
 * @author Sarah van der Laan
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _ourView.getSelectionCells();
    QueryNode currNode = (QueryNode) currentSelection[0];
    String queryString = currNode.getQuery();
    String entityNodeName = null;
    // find corresponding entity node name
    String[] tokens = queryString.split("\\s+");
    for (int i = 0; i < tokens.length; i++) {
        if (tokens[i].equalsIgnoreCase("from")) {
            entityNodeName = tokens[i + 1];
        }
    }
    EntityNode _ourEntityNode = null;
    // set corresponding node in order to use
    for (EntityNode node : _ourSketch.getEntities()) {
        if (node.getName().equalsIgnoreCase(entityNodeName)) {
            _ourEntityNode = node;
        }
    }
    if (!_ourSketch.hasDatabase()) {
        JOptionPane.showMessageDialog(null, "Not currently connected to a database.");
        return;
    } else {
        UpdateMonitor um = _ourSketch.getDatabase().newUpdateMonitor();
        if (um == null) {
            JOptionPane.showMessageDialog(null, "Could not perform update: problem accessing db driver");
            return;
        }
        if (_ourEntityNode != null)
            um.updateRow(_ourEntityNode);
    }
}
Also used : UpdateMonitor(easik.ui.datamanip.UpdateMonitor) QueryNode(easik.view.vertex.QueryNode) EntityNode(easik.sketch.vertex.EntityNode)

Example 3 with QueryNode

use of easik.view.vertex.QueryNode in project fql by CategoricalData.

the class DefineQueryNodeFromTreeAction method actionPerformed.

/**
 * Fires updateNode(QueryNode ourNode) with the current selection, should
 * its size be equal to 1.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theFrame.getMModel().getSelectionCells();
    if (currentSelection.length != 1) {
        return;
    }
    DefaultMutableTreeNode selected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
    if (selected.getUserObject() instanceof QueryNode) {
        updateNode((QueryNode) selected.getUserObject());
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) QueryNode(easik.view.vertex.QueryNode)

Example 4 with QueryNode

use of easik.view.vertex.QueryNode in project fql by CategoricalData.

the class DeleteFromViewFromTreeAction method actionPerformed.

/**
 * When the action is performed, selection is deleted if possible. Error is
 * displayed if no graph item is selected.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    int op = JOptionPane.showConfirmDialog(_theFrame, "Are you sure you want to delete the selected items?", "Confirm Deletion", JOptionPane.YES_NO_OPTION);
    if (op == JOptionPane.YES_OPTION) {
        Object[] currentSelection = _theFrame.getMModel().getSelectionCells();
        if (currentSelection.length == 0) {
            JOptionPane.showMessageDialog(_theFrame, "Operation must be performed with something selected", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            DefaultMutableTreeNode selected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
            if (selected.getUserObject() instanceof QueryNode) {
                _theFrame.getMModel().removeNode((QueryNode) selected.getUserObject());
            }
            _theFrame.getMModel().setDirty();
        }
        // Clear selection after things have been deleted
        _theFrame.getMModel().clearSelection();
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) QueryNode(easik.view.vertex.QueryNode)

Example 5 with QueryNode

use of easik.view.vertex.QueryNode in project fql by CategoricalData.

the class DefineQueryNodeAction method actionPerformed.

/**
 * Fires updateNode(QueryNode ourNode) with the current selection, should
 * its size be equal to 1.
 *
 * @param e
 *            The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
    Object[] currentSelection = _theFrame.getMModel().getSelectionCells();
    if (currentSelection.length != 1) {
        return;
    }
    QueryNode ourNode = (QueryNode) currentSelection[0];
    updateNode(ourNode);
}
Also used : QueryNode(easik.view.vertex.QueryNode)

Aggregations

QueryNode (easik.view.vertex.QueryNode)18 View_Edge (easik.view.edge.View_Edge)8 EntityNode (easik.sketch.vertex.EntityNode)5 InjectiveViewEdge (easik.view.edge.InjectiveViewEdge)5 PartialViewEdge (easik.view.edge.PartialViewEdge)5 ViewFrame (easik.ui.ViewFrame)4 SketchEdge (easik.sketch.edge.SketchEdge)3 UpdateMonitor (easik.ui.datamanip.UpdateMonitor)3 NormalViewEdge (easik.view.edge.NormalViewEdge)3 QueryException (easik.view.util.QueryException)3 DocumentInfo (easik.DocumentInfo)2 Sketch (easik.sketch.Sketch)2 View (easik.view.View)2 ViewGraphModel (easik.view.util.graph.ViewGraphModel)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 AttributeMap (org.jgraph.graph.AttributeMap)2 GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)2 ModelConstraint (easik.model.constraint.ModelConstraint)1 GuideEdge (easik.model.edge.GuideEdge)1 Cascade (easik.model.edge.ModelEdge.Cascade)1