use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.
the class SketchFrame method closeWindow.
/**
* Trys to close window as long it is not dirty.
*/
@Override
public void closeWindow() {
// We're exiting, so update the width/height of the main window, and
// save the settings
_settings.setProperty("sketch_display_width", String.valueOf(getWidth()));
_settings.setProperty("sketch_display_height", String.valueOf(getHeight()));
_settings.setProperty("sketch_divider_position", String.valueOf(_mainSplitPane.getDividerLocation()));
_settings.setProperty("sketch_frame_location_x", String.valueOf(getX()));
_settings.setProperty("sketch_frame_location_y", String.valueOf(getY()));
_settings.store();
// Refresh displayed thumbnail
_ourSketch.clearSelection();
_ourSketch.getOverview().refreshAll();
final ModelStateManager<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> stateManager = _ourSketch.getStateManager();
final SketchGraphModel sgm = _ourSketch.getGraphModel();
while (sgm.inInsignificantUpdate()) {
sgm.cancelInsignificantUpdate();
}
while (!(stateManager.peekState() instanceof BasicEditingState)) {
stateManager.popState();
}
setVisible(false);
}
use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.
the class ViewFrame method setQueryPopItems.
/**
*/
public void setQueryPopItems(QueryNode selected) {
// check to see if all nodes needed for this node to be updatable are
// present
boolean updateable = selected.isUpdateable();
if (!updateable) {
_ViewAddPopItem.setToolTipText("Queried entity node is not updatable");
_ViewQueryPopItem.setEnabled(true);
return;
} else {
for (EntityNode en : selected.getQueriedEntity().getDepend()) {
// System.out.println("Does view contain " + en.getName() +
// "?");
updateable = updateable && selected.getMModel().getEntityNodePairs().containsKey(en);
// System.out.println(selected.getMModel().getEntityNodePairs().containsKey(en));
}
if (!updateable) {
// was originally updatable but doesnt have require entitites
// don't allow insert
_ViewAddPopItem.setToolTipText(selected.getName() + " needs " + selected.getQueriedEntity().getDepend().toString() + " to be in view to be updatable.");
_ViewQueryPopItem.setEnabled(true);
_ViewUpdatePopItem.setEnabled(true);
_ViewDeletePopItem.setEnabled(true);
return;
} else {
// everything allowed
_ViewQueryPopItem.setEnabled(true);
_ViewUpdatePopItem.setEnabled(true);
_ViewDeletePopItem.setEnabled(true);
_ViewAddPopItem.setEnabled(true);
return;
}
}
}
use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.
the class JDBCUpdateMonitor method getDialogOptions.
/**
* Gets the options needed for open a dialog for row insertion: map of
* attribute names to their type, and a map of foreign key names to a JTable
* of data they point to.
*
* @param table
* The node representing the table who's information we want
* @return Wrapper class holding the maps needed for insertion dialog
*/
private DialogOptions getDialogOptions(final EntityNode table) {
@SuppressWarnings("unused") final HashSet<ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> constraints = new HashSet<ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>>(table.getConstraints());
final HashMap<String, EasikType> attToType = new HashMap<>(25);
final LinkedHashMap<String, EntityNode> fKeys = new LinkedHashMap<>(10);
// find attributes, and map to their EasikType
for (final EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> ea : table.getEntityAttributes()) {
attToType.put(ea.getName(), ea.getType());
}
// find all foreign keys, and add to foreign key set
for (final SketchEdge ske : table.getOutgoingEdges()) {
fKeys.put(cn.tableFK(ske), ske.getTargetEntity());
}
return new DialogOptions(attToType, fKeys);
}
use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.
the class JDBCUpdateMonitor method deleteFrom.
/**
* Trys to delete from a given table. If the action will break a constraint,
* it is aborted and the user is notified.
*
* @param table
* The table from which we will attempt the delete
* @return The success of the delete
*/
@Override
public boolean deleteFrom(final EntityNode table) {
final int[] selectedPKs = DatabaseUtil.selectRowPKs(table.getMModel().getFrame(), table);
// if there was a selection
if (selectedPKs.length > 0) {
final String PKcolumn = cn.tablePK(table);
final StringBuilder sb = new StringBuilder("DELETE FROM " + dbd.quoteId(table.getName()) + " WHERE ");
// populate input set for prepared statement while adding column
// names
final Set<ColumnEntry> input = new LinkedHashSet<>(selectedPKs.length);
for (final int pk : selectedPKs) {
for (EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> ea : table.getHiddenEntityAttributes()) {
try {
ResultSet result = dbd.executeQuery("SELECT * FROM " + table.getName() + " Where id=" + pk + " AND " + ea.getName() + "= 1");
// we do this by .isBeforeFirst()
if (result.isBeforeFirst()) {
JOptionPane.showMessageDialog(null, "Unable to execute DELETE: Deleting row will cause constraint inconsistency");
return false;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
sb.append(PKcolumn).append("=? OR ");
input.add(new ColumnEntry(PKcolumn, Integer.toString(pk), new Int()));
}
// remove last ',OR '
sb.delete(sb.length() - 4, sb.length());
try {
dbd.executePreparedUpdate(sb.toString(), input);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Unable to execute DELETE: " + e.getMessage());
}
}
return true;
}
use of easik.sketch.vertex.EntityNode in project fql by CategoricalData.
the class UpdateRowAction method actionPerformed.
/**
* Triggers JDBCUpdateMonitor to update a row in the selected table
*
* @param e
* The action event
*/
@Override
public void actionPerformed(ActionEvent e) {
Object[] currentSelection = _theSketch.getSelectionCells();
if (!(currentSelection[0] instanceof EntityNode)) {
return;
}
EntityNode node = (EntityNode) currentSelection[0];
UpdateMonitor um = _theSketch.getDatabase().newUpdateMonitor();
if (um == null) {
JOptionPane.showMessageDialog(null, "Could not perform update: problem accessing db driver");
return;
}
um.updateRow(node);
}
Aggregations