use of easik.sketch.util.graph.SketchGraphModel in project fql by CategoricalData.
the class XSDExporter method createConstraint.
/**
* Add an annotation explaining the sum constraint and effect the isAs.
* <p/>
* Today, this has two parts. First the annotation is truly just
* documentation in this case. The second part of the constraint creation,
* where the isA parts are added as elements of the type suffices to explain
* everything that is needed. In the standard sum constraint in
* constraints.easik gives this annotation:
*
* <pre>
* <xs:annotation>
* <xs:documentation>
* Sum is a disjoint generalization of Summand1 and Summand2 and Summand3
* </xs:documentation>
* </xs:annotation>
* </pre>
* <p/>
* Each of the Summand entities have an "isA" relationship to the Sum entity
* at the start of the diagram, so this is reflected in the typing. First,
* an element of each Summand type is added to the target of the "isA"
* relationship. Second, since there is no need for a separate element in
* the schema for the Summand entity, its element is removed from the sketch
* entity.
*
* @param sum
* the summand diagram constraint.
* @todo Why not do this with standard isA relationships as well?
*/
private static void createConstraint(final SumConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> sum) {
final Map<String, StringBuilder> codMap = new HashMap<>(10);
final Map<String, XSDType> codToXMLType = new HashMap<>(10);
XSDChoiceCompositor summands = new XSDChoiceCompositor(new ArrayList<XSDAbstractElement>(sum.getPaths().size()));
String cdTypeName = "";
XSDComplexType lastCodomainType = null;
for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : sum.getPaths()) {
final EntityNode coDomain = path.getCoDomain();
final EntityNode dom = path.getDomain();
final String coDomainName = coDomain.getName();
final StringBuilder coDomainAnnotation;
if (codMap.containsKey(coDomainName)) {
coDomainAnnotation = codMap.get(coDomainName);
coDomainAnnotation.append(" and ").append(dom.getName());
} else {
coDomainAnnotation = new StringBuilder(100);
coDomainAnnotation.append(coDomain.getName()).append(" is a disjoint generalization of ").append(dom.getName());
}
final XSDComplexType codomainType = (XSDComplexType) coDomain.getXsdType();
if ((null != lastCodomainType) && !cdTypeName.equals(codomainType.getName())) {
if (!summands.isEmpty()) {
lastCodomainType.addAtom(summands);
summands = new XSDChoiceCompositor(new ArrayList<XSDAbstractElement>(sum.getPaths().size()));
}
}
lastCodomainType = codomainType;
cdTypeName = codomainType.getName();
codToXMLType.put(coDomainName, codomainType);
codMap.put(coDomainName, coDomainAnnotation);
final XSDElement element = dom.getXsdElement();
element.setParent(coDomain.getXsdElement());
summands.addSubElement(element);
dom.setXsdElement(null);
}
if (null != lastCodomainType) {
if (!summands.isEmpty()) {
lastCodomainType.addAtom(summands);
summands = null;
}
}
for (final Map.Entry<String, StringBuilder> entry : codMap.entrySet()) {
final XSDType typ = codToXMLType.get(entry.getKey());
typ.addAnnotation(new XSDAnnotation(entry.getValue().toString()));
}
}
use of easik.sketch.util.graph.SketchGraphModel in project fql by CategoricalData.
the class XSDExporter method createConstraint.
/**
* Add an annotation explaining the pullback.
* <p/>
* Today, this is simply done by creating an annotation. For example in the
* standard pullback constraint in constraints.easik gives this annotation:
*
* <pre>
* <xs:annotation>
* <xs:documentation>
* ForAll.elemA in B, ForAll.elemB in C :
* elemA.f1 in A=elemB.isA_1 in A
* ==> Exists.p=(elemA,elemB) in Pullback
* </xs:documentation>
* </xs:annotation>
* </pre>
*
* @param pb
* the product diagram constraint.
*/
private void createConstraint(final PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> pb) {
final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = pb.getPaths();
final EntityNode dom = paths.get(0).getDomain();
final XSDType domType = dom.getXsdType();
final List<String> elts = new ArrayList<>(paths.size());
@SuppressWarnings("unused") final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
final List<String> values = new ArrayList<>();
final List<String> equalities = new ArrayList<>();
// WPBEDIT CF2012
for (int i = 0; i < pb.getWidth(); i++) {
final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path = pb.getFullPath(i);
final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
tmpPath.removeFirst();
values.add("ForAll.elem" + i + " in " + xmlPBJoinPath(tmpPath, false));
equalities.add("elem" + i + '.' + xmlPBelemJoinPath(tmpPath, true));
elts.add("elem" + i);
}
final String valdocumentation = EasikTools.join(", ", values);
final String equalDoc = EasikTools.join("=", equalities);
final String elements = "==> Exists.p=(" + EasikTools.join(",", elts) + ") in " + dom.getName();
domType.addAnnotation(new XSDAnnotation(valdocumentation + " : " + lineSep + equalDoc + lineSep + elements));
}
use of easik.sketch.util.graph.SketchGraphModel in project fql by CategoricalData.
the class XSDExporter method createConstraint.
/**
* Add an annotation explaining the product.
* <p/>
* Today, this is simply done by creating an annotation. For example in the
* standard product constraint in constraints.easik gives this annotation:
*
* <pre>
* <xs:annotation>
* <xs:documentation>
* ForAll.elem1 in (P1), ForAll.elem2 in (P2)
* Exists.p=(elem1,elem2) in Product
* </xs:documentation>
* </xs:annotation>
* </pre>
*
* @param prod
* the product diagram constraint.
*/
private void createConstraint(final ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> prod) {
final List<ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> paths = prod.getPaths();
final EntityNode dom = paths.get(0).getDomain();
final XSDType domType = dom.getXsdType();
final List<String> elts = new ArrayList<>(paths.size());
int id = 0;
@SuppressWarnings("unused") final String keyrefName = Easik.getInstance().getSettings().getProperty("xml_keyref_name");
final List<String> values = new ArrayList<>(paths.size());
for (final ModelPath<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> path : paths) {
id++;
final LinkedList<SketchEdge> tmpPath = new LinkedList<>(path.getEdges());
tmpPath.removeFirst();
final String elem = "elem" + id;
elts.add(elem);
if (tmpPath.size() == 0) {
values.add("ForAll." + elem + " in (" + path.getCoDomain().getName() + ')');
} else {
values.add("ForAll." + elem + " in " + xmlJoinPath(tmpPath, true));
}
}
final String documentation = EasikTools.join(", ", values);
final String elements = "Exists.p=(" + EasikTools.join(",", elts) + ") in " + dom.getName();
domType.addAnnotation(new XSDAnnotation(documentation + lineSep + elements));
}
use of easik.sketch.util.graph.SketchGraphModel in project fql by CategoricalData.
the class JDBCExporter method createConstraints.
/**
* Generates db constraints from the sketch constraints. This method is not
* generally overridden by drivers: the individual createConstraint(...)
* methods are called for each existing constraint.
*
* @return list of queries to create the constraints.
*/
protected List<String> createConstraints() {
final List<String> constraintSQL = new LinkedList<>();
final List<ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>> constraints = new ArrayList<>(sketch.getConstraints().values());
int id = 0;
for (final ModelConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> c : constraints) {
id++;
if (c instanceof CommutativeDiagram) {
constraintSQL.addAll(createConstraint((CommutativeDiagram<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c, String.valueOf(id)));
} else if (c instanceof ProductConstraint) {
constraintSQL.addAll(createConstraint((ProductConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c, String.valueOf(id)));
} else if (c instanceof PullbackConstraint) {
constraintSQL.addAll(createConstraint((PullbackConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c, String.valueOf(id)));
} else if (c instanceof EqualizerConstraint) {
constraintSQL.addAll(createConstraint((EqualizerConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c, String.valueOf(id)));
} else if (c instanceof SumConstraint) {
constraintSQL.addAll(createConstraint((SumConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c, String.valueOf(id)));
} else if (c instanceof LimitConstraint) {
constraintSQL.addAll(createConstraint((LimitConstraint<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>) c, String.valueOf(id)));
} else {
System.err.println("Unknown constraint type encountered: " + c.getClass());
}
}
return constraintSQL;
}
use of easik.sketch.util.graph.SketchGraphModel in project fql by CategoricalData.
the class SketchFrame method buildMenu.
/**
* Builds the menu
*/
private void buildMenu() {
final JMenuBar mainMenu;
final JMenu menuFile;
final JMenu menuHelp;
mainMenu = new JMenuBar();
// Make the File Menu
menuFile = new JMenu("File");
mainMenu.add(menuFile);
menuFile.setMnemonic(KeyEvent.VK_F);
final JMenu exportMenu = new JMenu("Export to");
menuFile.add(exportMenu);
// Export to server:
addMenuItem(exportMenu, new JMenuItem(new ExportDatabaseAction(this, _ourSketch)), KeyEvent.VK_D);
// Export to SQL text dump:
addMenuItem(exportMenu, new JMenuItem(new ExportFileAction(this, _ourSketch)), KeyEvent.VK_F);
addMenuItem(exportMenu, new JMenuItem(new ExportImageAction<>(this)), null);
addMenuItem(exportMenu, new JMenuItem(new SketchExportAction(this)), null);
menuFile.addSeparator();
addMenuItem(menuFile, new JMenuItem(new DocumentInfoAction(this)), KeyEvent.VK_I);
menuFile.addSeparator();
addMenuItem(menuFile, new JMenuItem(new FileQuitAction(this)), KeyEvent.VK_W);
// Make the Edit menu for "edit mode"
menuEditEdit = new JMenu("Edit");
mainMenu.add(menuEditEdit);
addMenuItem(menuEditEdit, _UndoItem = new JMenuItem(new UndoAction(_ourSketch)), KeyEvent.VK_Z);
addMenuItem(menuEditEdit, _RedoItem = new JMenuItem(new RedoAction(_ourSketch)), KeyEvent.VK_Y);
menuEditEdit.addSeparator();
menuEditEdit.add(menuEditAdd = new JMenu("Add"));
addMenuItem(menuEditAdd, _AddEntityItem = new JMenuItem(new NewEntityAction<>(null, this)), null);
menuEditAdd.add(menuEditAddEdge = new JMenu("Add edge"));
addMenuItem(menuEditAddEdge, addEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.NORMAL)), null);
addMenuItem(menuEditAddEdge, addInjEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.INJECTIVE)), null);
addMenuItem(menuEditAddEdge, addParEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.PARTIAL)), null);
addMenuItem(menuEditAddEdge, addSelfParEdge = new JMenuItem(new NewSketchEdgeAction(this, Edge.SELF)), null);
addMenuItem(menuEditAdd, addAtt = new JMenuItem(new AddAttributeAction<>(this)), null);
addMenuItem(menuEditAdd, addUK = new JMenuItem(new AddUniqueKeyAction<>(this)), null);
addMenuItem(menuEditEdit, del = new JMenuItem(new DeleteFromSketchAction(this)), null);
addMenuItem(menuEditEdit, rename = new JMenuItem(new RenameInSketchAction(this)), KeyEvent.VK_R);
menuEditEdit.add(new JSeparator());
addMenuItem(menuEditEdit, editEdge = new JMenuItem(new EditSketchEdgeAction(this)), KeyEvent.VK_E);
menuEditEdit.add(new JSeparator());
// If
addMenuItem(menuEditEdit, _ProgramSettingsItem = new JMenuItem("Preferences"), KeyEvent.VK_P);
// you
// change
// this
// title,
// update
// OSX.java
_ProgramSettingsItem.setToolTipText("Set global EASIK preferences");
_ProgramSettingsItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e1) {
final ProgramSettingsUI myUI = new ProgramSettingsUI(SketchFrame.this);
myUI.showDialog();
}
});
// add listener to enable appropriate menu items
menuEditEdit.addMenuListener(new MenuListener() {
@Override
public void menuCanceled(final MenuEvent e) {
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuSelected(final MenuEvent e) {
final Object[] selection = _ourSketch.getSelectionCells();
final SketchGraphModel model = _ourSketch.getGraphModel();
final boolean undoable = model.canUndo() && !_ourSketch.getDatabase().hasConnection() && !_ourSketch.isSynced();
final boolean redoable = model.canRedo() && !_ourSketch.getDatabase().hasConnection() && !_ourSketch.isSynced();
_UndoItem.setEnabled(undoable);
_RedoItem.setEnabled(redoable);
menuEditAdd.setEnabled(true);
menuEditAddEdge.setEnabled(true);
_AddEntityItem.setEnabled(false);
addEdge.setEnabled(false);
addInjEdge.setEnabled(false);
addParEdge.setEnabled(false);
addSelfParEdge.setEnabled(false);
addAtt.setEnabled(false);
addUK.setEnabled(false);
rename.setEnabled(false);
del.setEnabled(false);
editEdge.setEnabled(false);
if (selection.length == 0) {
_AddEntityItem.setEnabled(true);
menuEditAddEdge.setEnabled(false);
}
if (selection.length >= 1) {
del.setEnabled(true);
if (selection.length == 1) {
if (selection[0] instanceof EntityNode) {
rename.setEnabled(true);
}
if (selection[0] instanceof EntityNode) {
addSelfParEdge.setEnabled(true);
addAtt.setEnabled(true);
addUK.setEnabled(true);
} else if (selection[0] instanceof SketchEdge) {
editEdge.setEnabled(true);
}
}
// if selection contains an edge, dissable edit|add...
for (int i = 0; i < selection.length; i++) {
if (selection[i] instanceof SketchEdge) {
menuEditAdd.setEnabled(false);
}
}
if (selection.length >= 3) {
menuEditAdd.setEnabled(false);
}
}
if ((selection.length == 2) && (selection[0] instanceof EntityNode) && (selection[1] instanceof EntityNode)) {
addEdge.setEnabled(true);
addInjEdge.setEnabled(true);
addParEdge.setEnabled(true);
}
}
});
// Make the Edit menu for "manipulate mode"
@SuppressWarnings("unused") final JMenuItem updateRowMenuItem;
@SuppressWarnings("unused") final JMenuItem viewDataMenuItem;
menuEditManip = new JMenu("Edit");
mainMenu.add(menuEditManip);
menuEditManip.add(addRowMenuItem = new JMenuItem(new AddRowAction(_ourSketch)));
menuEditManip.add(insertQueryMenuItem = new JMenuItem(new ExecPreparedInsertAction(_ourSketch)));
menuEditManip.addSeparator();
menuEditManip.add(updateRowMenuItem = new JMenuItem(new UpdateRowAction(_ourSketch)));
menuEditManip.addSeparator();
menuEditManip.add(deleteRowMenuItem = new JMenuItem(new DeleteRowAction(_ourSketch)));
menuEditManip.add(deleteQueryMenuItem = new JMenuItem(new ExecPreparedDeleteAction(_ourSketch)));
menuEditManip.addSeparator();
menuEditManip.add(viewDataMenuItem = new JMenuItem(new ViewDataAction(_ourSketch)));
menuEditManip.addMenuListener(new MenuListener() {
@Override
public void menuCanceled(final MenuEvent e) {
}
@Override
public void menuDeselected(final MenuEvent e) {
}
@Override
public void menuSelected(final MenuEvent e) {
final Object[] selection = _ourSketch.getSelectionCells();
final boolean enable = (selection.length == 1) && (selection[0] instanceof EntityNode);
for (final Component c : menuEditManip.getMenuComponents()) {
c.setEnabled(enable);
}
if (!enable) {
return;
}
if (!_ourSketch.editable((EntityNode) selection[0])) {
addRowMenuItem.setEnabled(false);
insertQueryMenuItem.setEnabled(false);
deleteRowMenuItem.setEnabled(false);
deleteQueryMenuItem.setEnabled(false);
}
}
});
menuView = new JMenu("View");
mainMenu.add(menuView);
menuView.add(_ShowAttributesToggle = new JCheckBoxMenuItem("Attributes/keys visible"));
_ShowAttributesToggle.setToolTipText("Toggle display of attributes and unique keys");
_ShowAttributesToggle.setState("show".equals(Easik.getInstance().getSettings().getProperty("attrib_display", "show")));
_ShowAttributesToggle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e1) {
_ourSketch.refresh();
}
});
menuView.add(_ShowConstraintToggle = new JCheckBoxMenuItem("Constraints visible"));
_ShowConstraintToggle.setToolTipText("Toggle display of constraints");
_ShowConstraintToggle.setState(true);
_ShowConstraintToggle.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e1) {
ModelConstraint.setAllConstraintsVisible(_ourSketch.getConstraints(), _ShowConstraintToggle.getState());
}
});
// Create constraints menu
menuConstraint = new JMenu("Constraints");
menuConstraint.setMnemonic(KeyEvent.VK_C);
mainMenu.add(menuConstraint);
addMenuItem(menuConstraint, _AddCommutativeDiagramMenuItem = new JMenuItem(new AddCommutativeDiagramAction<>(this)), null);
addMenuItem(menuConstraint, _AddSumMenuItem = new JMenuItem(new AddSumConstraintAction<>(this)), null);
addMenuItem(menuConstraint, _AddProductMenuItem = new JMenuItem(new AddProductConstraintAction<>(this)), null);
addMenuItem(menuConstraint, _AddPullbackMenuItem = new JMenuItem(new AddPullbackConstraintAction<>(this)), null);
addMenuItem(menuConstraint, _AddEqualizerMenuItem = new JMenuItem(new AddEqualizerConstraintAction(this)), null);
// addMenuItem(menuConstraint, _AddLimMenuItem = new JMenuItem(new
// AddLimitConstraintAction<SketchFrame,
// SketchGraphModel,Sketch,EntityNode, SketchEdge>(this)), null);
// Make SQL connection menu
menuSQL = new JMenu("SQL Connection");
menuSQL.setMnemonic(KeyEvent.VK_S);
mainMenu.add(menuSQL);
addMenuItem(menuSQL, new JMenuItem(new DisconnectAction(_ourSketch)), null);
// DTRIG
addMenuItem(menuSQL, new JMenuItem(new OverrideConstraintAction(_ourSketch)), null);
// CF2012
// Create help menu
menuHelp = new JMenu("Help");
mainMenu.add(menuHelp);
menuHelp.setMnemonic(KeyEvent.VK_H);
menuHelp.add(new HelpAction());
menuHelp.add(new AboutAction());
setJMenuBar(mainMenu);
}
Aggregations