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;
}
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);
}
}
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());
}
}
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();
}
}
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);
}
Aggregations