use of easik.view.edge.View_Edge 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.edge.View_Edge in project fql by CategoricalData.
the class OverviewHandler method startElement.
/**
* Overloaded method that is called any time the start of an element is
* found
*
* @param namespace
* @see org.xml.sax.helpers.DefaultHandler
* @param localName
* @see org.xml.sax.helpers.DefaultHandler
* @param qName
* @see org.xml.sax.helpers.DefaultHandler
* @param atts
* @see org.xml.sax.helpers.DefaultHandler
*/
@Override
public void startElement(String namespace, String localName, String qName, Attributes atts) {
_currNode = qName;
// call
if (_sketchParser != null) {
_sketchParser.startElement(namespace, localName, qName, atts);
} else // Initialize a sketch handler, and note this sketch's attributes
if (qName.equals("easketch")) {
String sketchName = atts.getValue("name");
int sketchX = Integer.parseInt(atts.getValue("x"));
int sketchY = Integer.parseInt(atts.getValue("y"));
String cascade = atts.getValue("cascade"), pCascade = atts.getValue("partial-cascade");
if (cascade == null) {
cascade = Easik.getInstance().getSettings().getProperty("sql_cascade", "restrict");
}
if (pCascade == null) {
pCascade = Easik.getInstance().getSettings().getProperty("sql_cascade_partial", "set_null");
}
Cascade c = cascade.equals("cascade") ? Cascade.CASCADE : Cascade.RESTRICT;
Cascade cp = pCascade.equals("cascade") ? Cascade.CASCADE : pCascade.equals("restrict") ? Cascade.RESTRICT : Cascade.SET_NULL;
_sketchParser = SketchFileIO.getNewSketchHandler(_theFrame.getOverview());
SketchFrame frame = _sketchParser.getFrame();
Sketch sketch = frame.getMModel();
sketch.setDefaultCascading(c);
sketch.setDefaultPartialCascading(cp);
_newSketchNode = new SketchNode(sketchName, sketchX, sketchY, frame);
_sketchNodes.put(sketchName, _newSketchNode);
} else // know not to override the overview's
if (qName.equals("view")) {
_parsingView = true;
_queryNodes = new HashMap<>();
String viewName = atts.getValue("name");
int x = Integer.parseInt(atts.getValue("x"));
int y = Integer.parseInt(atts.getValue("y"));
String edgeLabel = atts.getValue("viewDefinitionEdge");
String sketchName = atts.getValue("on_sketch");
ViewFrame viewFrame = new ViewFrame(_theFrame.getOverview(), _sketchNodes.get(sketchName).getFrame().getMModel());
_newViewNode = new ViewNode(viewName, x, y, viewFrame);
_viewDefEdge.put(edgeLabel, new ViewDefinitionEdge(_newViewNode, _sketchNodes.get(sketchName), edgeLabel));
_viewDocInfo = new DocumentInfo(viewFrame);
_viewNodes.put(viewName, _newViewNode);
_sketchNodes.get(sketchName).getFrame().getMModel().addView(_newViewNode);
} else if (qName.equals("queryNode")) {
String name = atts.getValue("name");
int x = Integer.parseInt(atts.getValue("x"));
int y = Integer.parseInt(atts.getValue("y"));
String query = atts.getValue("query");
// exception so they can't be saved
try {
_queryNodes.put(name, new QueryNode(name, x, y, _newViewNode.getFrame().getMModel(), query));
} catch (QueryException e) {
e.printStackTrace();
}
} else if (qName.equals("View_Edge")) {
View_Edge newEdge;
String edgeType = atts.getValue("type");
QueryNode source = _queryNodes.get(atts.getValue("source"));
QueryNode target = _queryNodes.get(atts.getValue("target"));
String id = atts.getValue("id");
String cascadeAtt = atts.getValue("cascade");
if (cascadeAtt == null) {
// This is from an export before Easik had per-edge cascading
// (in other words, before r583)
// We use the global preferences for cascading
String key = "sql_cascade", def = "restrict";
if (edgeType.equals("partial")) {
key = "sql_cascade_partial";
def = "set_null";
}
cascadeAtt = Easik.getInstance().getSettings().getProperty(key, def);
}
@SuppressWarnings("unused") SketchEdge.Cascade cascade = cascadeAtt.equals("set_null") ? SketchEdge.Cascade.SET_NULL : cascadeAtt.equals("cascade") ? SketchEdge.Cascade.CASCADE : SketchEdge.Cascade.RESTRICT;
if (edgeType.equals("injective")) {
newEdge = new InjectiveViewEdge(source, target, id);
} else if (edgeType.equals("partial")) {
newEdge = new PartialViewEdge(source, target, id);
} else {
newEdge = new NormalViewEdge(source, target, id);
}
_viewEdges.put(id, newEdge);
}
}
use of easik.view.edge.View_Edge in project fql by CategoricalData.
the class ViewGraphModel method getAttributes.
/**
* Overridden method to get cell attributes; we make sure the appropriate
* attributes are applied to the Easik objects before returning them.
*
* @see DefaultGraphModel.getAttributes(Object)
*
* @param o
*
* @return
*/
@Override
@SuppressWarnings("unchecked")
public AttributeMap getAttributes(Object o) {
_mode = (_view.getSketch().getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
if (o instanceof GraphCell) {
GraphCell cell = (GraphCell) o;
AttributeMap attribs = cell.getAttributes();
AttributeMap easikAttribs = null;
if (cell instanceof View_Edge) {
easikAttribs = (cell instanceof InjectiveViewEdge) ? injectiveEdgeAttributes() : (cell instanceof PartialViewEdge) ? partialEdgeAttributes() : normalEdgeAttributes();
} else if (cell instanceof TriangleEdge) {
easikAttribs = triangleEdgeAttributes((TriangleEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell);
} else if (cell instanceof GuideEdge) {
easikAttribs = ((GuideEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell).isHighlighted() ? virtualHighlightedEdgeAttributes() : virtualEdgeAttributes();
} else if (cell instanceof ModelConstraint) {
easikAttribs = virtualVertexAttributes();
} else if (cell instanceof QueryNode) {
easikAttribs = vertexAttributes();
}
if (easikAttribs != null) {
if (_view.isCellSelected(cell)) {
Color selColor;
float lineWidth;
if (_view.getStateManager().peekState() instanceof GetPathState) {
selColor = getColor("path_selection");
lineWidth = getWidth("path_selection", 2);
} else {
selColor = getColor("selection");
lineWidth = getWidth("selection", 3);
}
int borderWidth = getIntWidth(_mode + ((cell instanceof ModelConstraint) ? "constraint" : "entity") + "_border", 1);
GraphConstants.setBorder(easikAttribs, BorderFactory.createLineBorder(selColor, borderWidth));
GraphConstants.setForeground(easikAttribs, selColor);
GraphConstants.setLineColor(easikAttribs, selColor);
GraphConstants.setLineWidth(easikAttribs, lineWidth);
}
if (attribs == null) {
cell.setAttributes(easikAttribs);
attribs = easikAttribs;
} else {
attribs.applyMap(easikAttribs);
}
return attribs;
}
}
return super.getAttributes(o);
}
use of easik.view.edge.View_Edge in project fql by CategoricalData.
the class View method autoAddExistingEdges.
/**
* Call this method when a new QueryNode or Edge is created to automatically
* add whatever existing edges It has in the underlying sketch with other
* existing QueryNodes.
*
* @author Federico Mora
*/
public void autoAddExistingEdges() {
Collection<SketchEdge> sketchEdges = _ourSketch.getEdges().values();
HashMap<EntityNode, QueryNode> nodeMatches = getEntityNodePairs();
for (SketchEdge se : sketchEdges) {
if (nodeMatches.containsKey(se.getTargetEntity()) && nodeMatches.containsKey(se.getSourceEntity()) && !_edges.containsKey(se.getName())) {
View_Edge vEdge;
// need to move down??
if (se.isPartial()) {
vEdge = new PartialViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
} else if (se.isInjective()) {
// System.out.println("Edge is injective");
// **NEED TO FIGURE OUT CASCADING
vEdge = new InjectiveViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName(), Cascade.RESTRICT);
} else {
vEdge = new NormalViewEdge(nodeMatches.get(se.getSourceEntity()), nodeMatches.get(se.getTargetEntity()), se.getName());
}
this.addEdge(vEdge);
}
}
}
use of easik.view.edge.View_Edge in project fql by CategoricalData.
the class View method removeNode.
/**
* Removes an entity, and also cascades to remove all the arrows involved
* with it.
*
* @param toRemove
* The entity about to be removed
*/
@Override
public void removeNode(final QueryNode toRemove) {
// So we don't get a ConcurrentModificationException
final ArrayList<View_Edge> removeEdges = new ArrayList<>();
for (final View_Edge edge : _edges.values()) {
if (edge.getSourceQueryNode().equals(toRemove) || edge.getTargetQueryNode().equals(toRemove)) {
// add the edge to a list of edges to remove
removeEdges.add(edge);
}
}
model.beginUpdate();
// Remove the edges
for (final View_Edge e : removeEdges) {
removeEdge(e);
}
// remove the constraints this queryNode is a part of
for (ModelConstraint<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge> c : toRemove.getConstraints()) {
if (_constraints.containsKey(c.getID())) {
this.removeConstraint(c);
}
}
_nodes.remove(toRemove.toString());
getGraphLayoutCache().remove(new Object[] { toRemove });
// Remove Entity from tree
_Frame.getInfoTreeUI().removeNode(toRemove);
model.endUpdate();
}
Aggregations