use of easik.model.vertex.ModelVertex in project fql by CategoricalData.
the class AddAttributeAction method actionPerformed.
/**
* Inserts an attribute to the currently selected entity (or parent entity
* if attribute is selected) in the tree
*
* @param e
* The action event
*/
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
// cancel operation
if (_theFrame.getMModel().isSynced()) {
int choice = JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (choice == JOptionPane.CANCEL_OPTION) {
return;
}
}
// Get currently selected object
Object[] selected = _theFrame.getMModel().getSelectionCells();
N curEntity;
// Check what is currently selected
if ((selected.length == 1) && (selected[0] instanceof ModelVertex)) {
// Entity is selected so set it as current entity
curEntity = (N) selected[0];
} else {
JOptionPane.showMessageDialog(_theFrame, "You do not have an entity selected. \nPlease select a single entity and try again.", "No Entity Selected", JOptionPane.ERROR_MESSAGE);
return;
}
AttributeUI<F, GM, M, N, E> myUI = new AttributeUI<>(_theFrame, curEntity);
if (myUI.isAccepted()) {
// Get values from dialog
String newAttName = myUI.getName();
EasikType newAttType = myUI.getCustomType();
// Create Entity Attribute
EntityAttribute<F, GM, M, N, E> newAtt = new EntityAttribute<>(newAttName, newAttType, curEntity);
// Add attribute to entity
curEntity.addEntityAttribute(newAtt);
// TODO
/*
* need to find way to do this now with generics. Want to add to
* queryNodes when adding to entityNode
*
* for(ViewNode vn :_theFrame.getMModel().getViews()){ HashMap<N,
* QueryNode> nodePairs = vn.getMModel().getEntityNodePairs();
* //potentially throws QueryException but won't in this case since
* we are just adding attributes try {
* nodePairs.get(curEntity).processAttributes(); } catch
* (QueryException e1) { e1.printStackTrace(); } }
*/
// Refresh view of
_theFrame.getInfoTreeUI().refreshTree(curEntity);
// entity
_theFrame.getMModel().clearSelection();
_theFrame.getMModel().setDirty();
_theFrame.getMModel().setSynced(false);
}
}
use of easik.model.vertex.ModelVertex 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.vertex.ModelVertex in project fql by CategoricalData.
the class DeleteEntityAction method actionPerformed.
/**
* Called when clicked upon, will delete entity.
*
* @param e
* The action event
*/
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
// If there is nothing seleceted then just do nothing
if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
return;
}
// Get M object
M _ourModel = _theFrame.getMModel();
// cancel operation
if (_ourModel.isSynced()) {
int choice = JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (choice == JOptionPane.CANCEL_OPTION) {
return;
}
}
// Get currently selected object
DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
if (curSelected instanceof ModelVertex) {
_theFrame.getMModel().removeNode((N) curSelected);
_theFrame.getMModel().setDirty();
_theFrame.getMModel().setSynced(false);
}
}
use of easik.model.vertex.ModelVertex in project fql by CategoricalData.
the class RenameEntityAction method actionPerformed.
/**
* Called when clicked upon, will rename an article.
*
* @param e
* The action event
*/
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) {
// If there is nothing seleceted then just do nothing
if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
return;
}
// Get M object
M _ourModel = _theFrame.getMModel();
// cancel operation
if (_ourModel.isSynced()) {
int choice = JOptionPane.showConfirmDialog(_theFrame, "Warning: this sketch is currently synced with a db; continue and break synchronization?", "Warning!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (choice == JOptionPane.CANCEL_OPTION) {
return;
}
}
// Get currently selected object
DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
N nodeToRename;
String originalName = "";
// Check what is currently selected
if (curSelected instanceof ModelVertex) {
nodeToRename = (N) curSelected;
originalName = nodeToRename.getName();
} else {
return;
}
String s = (String) JOptionPane.showInputDialog(_ourModel.getParent(), "New name:", "Rename", JOptionPane.QUESTION_MESSAGE, null, null, originalName);
if (s != null) {
s = s.trim();
if (s.equals("")) {
JOptionPane.showMessageDialog(_theFrame, "Entity name is empty", "Error", JOptionPane.ERROR_MESSAGE);
} else if (_ourModel.isNameUsed(s)) {
JOptionPane.showMessageDialog(_theFrame, "Entity name is already in use", "Error", JOptionPane.ERROR_MESSAGE);
} else {
// Push loading state
_ourModel.getStateManager().pushState(new LoadingState<>(_ourModel));
nodeToRename.setName(s);
_theFrame.getInfoTreeUI().refreshTree();
_theFrame.getMModel().getGraphLayoutCache().reload();
// Pop state
_ourModel.getStateManager().popState();
_ourModel.repaint();
_ourModel.setDirty();
_ourModel.setSynced(false);
}
}
_ourModel.clearSelection();
}
use of easik.model.vertex.ModelVertex in project fql by CategoricalData.
the class ModelVertexRenderer method getRendererComponent.
/**
* Returns the renderer component after initializing it
*
* @param graph
* The graph (really a M in disguise)
* @param view
* The cell view
* @param sel
* If the view is selected or not
* @param focus
* If the view has focus or not
* @param preview
* If the graph is in preview mode or not
* @return The renderer component fully initialized
*/
@Override
@SuppressWarnings("unchecked")
public Component getRendererComponent(JGraph graph, CellView view, boolean sel, boolean focus, boolean preview) {
this.model = (M) graph;
this.selected = sel;
this.preview = preview;
this.hasFocus = focus;
ModelVertex<F, GM, M, N, E> v = (ModelVertex<F, GM, M, N, E>) view.getCell();
// doesn't paint anything
if ((v instanceof ModelConstraint) && !((ModelConstraint<F, GM, M, N, E>) v).isVisible()) {
return new JPanel() {
private static final long serialVersionUID = -8516030326162065848L;
@Override
public void paint(Graphics g) {
}
};
}
// may be because of int casting and off by one)
if ((int) (view.getBounds().getX()) != v.getX() || (int) (view.getBounds().getY()) != v.getY()) {
model.setDirty();
}
// Initialize panel
removeAll();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
// Add in entity/constraint label
add(_entity = new JPanel(new GridLayout(1, 1)));
_entity.add(_entityLabel = new JLabel(v.getName(), SwingConstants.CENTER));
N myNode = (N) v;
// Add in attributes
_attributes = new JPanel(new GridLayout(0, 1));
add(_attributes);
for (EntityAttribute<F, GM, M, N, E> att : myNode.getEntityAttributes()) {
_attributes.add(new JLabel(" @ " + att.getName()));
}
if ((_attributes.getComponentCount() == 0) || !model.getFrame().getShowAttsVal()) {
_attributes.setVisible(false);
}
// Add in unique keys
_uniqueKeys = new JPanel(new GridLayout(0, 1));
add(_uniqueKeys);
for (UniqueKey<F, GM, M, N, E> key : myNode.getUniqueKeys()) {
_uniqueKeys.add(new JLabel(" $ " + key.getKeyName()));
}
if ((_uniqueKeys.getComponentCount() == 0) || !model.getFrame().getShowAttsVal()) {
_uniqueKeys.setVisible(false);
}
@SuppressWarnings("rawtypes") Map attributes = view.getAllAttributes();
installAttributes(v, attributes);
// Set desired size
setSize(getPreferredSize());
return this;
}
Aggregations