use of easik.model.constraint.SumConstraint in project fql by CategoricalData.
the class SketchFrame method setEditConstraintPopItems.
/**
*/
public void setEditConstraintPopItems() {
// dissable all elements
for (final Component c : _editConstraintPopMenu.getComponents()) {
c.setEnabled(false);
}
// we always want delete
_DeleteConstraintPopItem.setEnabled(true);
final Object[] currentSelection = _ourSketch.getSelectionCells();
if (currentSelection.length == 1) {
if ((currentSelection[0] instanceof SumConstraint) || (currentSelection[0] instanceof ProductConstraint) || (currentSelection[0] instanceof CommutativeDiagram)) {
_AddPathPopItem.setEnabled(true);
}
}
}
use of easik.model.constraint.SumConstraint in project fql by CategoricalData.
the class ModelInfoTreeUI method _addConstraint.
/**
* Internal method that actually does the work of adding the constraint to
* the info tree; this is separate from the public method so that the public
* method can handle undo/redo controlling.
*
* @param constraint
*/
private void _addConstraint(ModelConstraint<F, GM, M, N, E> constraint) {
DefaultMutableTreeNode node = constraint.getTreeNode();
if (constraint instanceof ProductConstraint) {
_tree_constraints_product.add(node);
} else if (constraint instanceof SumConstraint) {
_tree_constraints_sum.add(node);
} else if (constraint instanceof PullbackConstraint) {
_tree_constraints_pullback.add(node);
} else if (constraint instanceof EqualizerConstraint) {
_tree_constraints_equalizer.add(node);
} else if (constraint instanceof CommutativeDiagram) {
_tree_constraints_commutative.add(node);
} else if (constraint instanceof LimitConstraint) {
_tree_constraints_limit.add(node);
}
// Add the paths to the constraint
for (ModelPath<F, GM, M, N, E> path : constraint.getPaths()) {
node.add(path);
}
refreshTree((DefaultMutableTreeNode) node.getParent());
}
use of easik.model.constraint.SumConstraint in project fql by CategoricalData.
the class JDBCViewUpdateMonitor method insert.
/**
* Determines if insertion into a given table requires special handling due
* to constraints it may be in. As of now, special cases that may result
* from being in multiple constraints are not supported.
*
* @param table
* The table into which we wish to insert data
* @return Success of the insertion
*/
@Override
public boolean insert(final EntityNode table) {
final DialogOptions dOpts = getDialogOptions(table);
final String lineSep = EasikTools.systemLineSeparator();
// a set of column-value pairs of which we wish to force a specific
// value, leaving the user out
final Set<ColumnEntry> forced = new HashSet<>(10);
// contstraint. Tighten up?
for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : table.getConstraints()) {
if (c instanceof SumConstraint) {
// of its foreign key, so remove it from the dialog's selection
for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> sp : c.getPaths()) {
if (sp.getDomain() == table) {
// we force the value 0 to avoid out driver to kick back
// an error for having a null fKey
final String columnName = cn.tableFK(sp.getFirstEdge());
dOpts.fKeys.remove(columnName);
forced.add(new ColumnEntry(columnName, "0", new Int()));
break;
}
}
}
if (c instanceof CommutativeDiagram) {
// commute
if (c.getPaths().get(0).getDomain() == table) {
JOptionPane.showMessageDialog(null, "Be sure that the following paths commute:" + lineSep + EasikTools.join(lineSep, c.getPaths()), "Commutative diagram", JOptionPane.INFORMATION_MESSAGE);
try {
return promptAndInsert(table, dOpts, forced);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Not all of the following paths commute -- insert aborted!" + lineSep + EasikTools.join(lineSep, c.getPaths()), "Commutative diagram failure", JOptionPane.ERROR_MESSAGE);
}
}
}
if (c instanceof PullbackConstraint) {
// happens, we want to let the user update the new record
if (((PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c).getTarget() != table) {
final EntityNode pullback = ((PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c).getSource();
try {
// get row count pre-insert
ResultSet result = dbd.executeQuery("SELECT COUNT(*) FROM " + pullback.getName() + " X");
result.next();
final int preRowCount = result.getInt(1);
if (!promptAndInsert(table, dOpts)) {
return false;
}
// get row count post-insert
result = dbd.executeQuery("SELECT COUNT(*) FROM " + pullback.getName() + " X");
result.next();
final int postRowCount = result.getInt(1);
// new row (the one with the highest primary ID)
if (postRowCount > preRowCount) {
result = dbd.executeQuery("SELECT MAX(" + cn.tablePK(pullback) + ") FROM " + pullback.getName() + " X");
result.next();
final int pk = result.getInt(1);
if (JOptionPane.showConfirmDialog(null, "New record in pullback table '" + pullback.getName() + "'. Enter column data?", "Insert column data?", JOptionPane.YES_NO_OPTION) == 0) {
updateRow(pullback, pk);
}
}
return true;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Could not execute update: " + e.getMessage());
}
}
}
if (c instanceof ProductConstraint) {
// inserting into the product.
for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> sp : c.getPaths()) {
if (sp.getCoDomain() == table) {
final EntityNode product = sp.getDomain();
try {
if (!promptAndInsert(table, dOpts)) {
return false;
}
// get the new records from the product. They are
// any record who's fk to our INSERT factor matches
// the primary id of the last insert
ResultSet result = dbd.executeQuery("SELECT MAX(" + cn.tablePK(table) + ") FROM " + table.getName() + " X");
result.next();
final int newPK = result.getInt(1);
result = dbd.executeQuery("SELECT * FROM " + product.getName() + " WHERE " + cn.tableFK(sp.getFirstEdge()) + " = " + newPK);
// get count of new rows as result of INSERT
result.last();
final int newRows = result.getRow();
result.beforeFirst();
if ((newRows > 0) && (JOptionPane.showConfirmDialog(null, newRows + " new rows in product table '" + product.getName() + "'. Insert column data?", "Insert column data?", JOptionPane.YES_NO_OPTION) == 0)) {
while (result.next()) {
updateRow(product, result.getInt(1));
}
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
return true;
}
}
}
if (c instanceof LimitConstraint) {
// TRIANGLES TODO CF2012 Incomplete
}
}
try {
return promptAndInsert(table, dOpts, forced);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Could not execute update: " + e.getMessage());
return false;
}
}
use of easik.model.constraint.SumConstraint 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;
}
use of easik.model.constraint.SumConstraint in project fql by CategoricalData.
the class ModelInfoTreeUI method _removeConstraint.
/**
* Internal method that actually does the work of adding the constraint to
* the info tree; this is separate from the public method so that the public
* method can handle undo/redo controlling.
*
* @param c
*/
private void _removeConstraint(ModelConstraint<F, GM, M, N, E> c) {
DefaultMutableTreeNode constraint = c.getTreeNode();
if (c instanceof CommutativeDiagram) {
_tree_constraints_commutative.remove(constraint);
} else if (c instanceof ProductConstraint) {
_tree_constraints_product.remove(constraint);
} else if (c instanceof PullbackConstraint) {
_tree_constraints_pullback.remove(constraint);
} else if (c instanceof EqualizerConstraint) {
_tree_constraints_equalizer.remove(constraint);
} else if (c instanceof SumConstraint) {
_tree_constraints_sum.remove(constraint);
} else if (c instanceof LimitConstraint) {
_tree_constraints_limit.remove(constraint);
}
refreshTree();
}
Aggregations