use of easik.model.attribute.AttributeUI 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.attribute.AttributeUI in project fql by CategoricalData.
the class EditAttributeAction method actionPerformed.
/**
* Brings up a dialog to edit the currently selected attribute
*
* @param e
* The action event
*/
@Override
public void actionPerformed(ActionEvent e) {
// If there is nothing seleceted then just do nothing
if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
return;
}
// 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
DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree().getSelectionPath().getLastPathComponent();
// Selection is an attribute
if (curSelected instanceof EntityAttribute) {
@SuppressWarnings("unchecked") EntityAttribute<F, GM, M, N, E> curAttribute = (EntityAttribute<F, GM, M, N, E>) curSelected;
// we can cast it because we will only edit in sketches
N parentEntity = curAttribute.getEntity();
AttributeUI<F, GM, M, N, E> myUI = new AttributeUI<>(_theFrame, parentEntity, curAttribute);
if (myUI.isAccepted()) {
// Get values from dialog
@SuppressWarnings("unused") String newAttName = myUI.getName();
@SuppressWarnings("unused") EasikType newAttType = myUI.getCustomType();
curAttribute.setName(myUI.getName());
curAttribute.setType(myUI.getCustomType());
_theFrame.getInfoTreeUI().refreshTree(parentEntity);
Object[] myCell = new Object[] { parentEntity };
_theFrame.getMModel().getGraphLayoutCache().hideCells(myCell, true);
_theFrame.getMModel().getGraphLayoutCache().showCells(myCell, true);
_theFrame.getMModel().repaint();
_theFrame.getMModel().setDirty();
_theFrame.getMModel().setSynced(false);
}
} else // Selection is not an attribute
{
JOptionPane.showMessageDialog(_theFrame, "You don't have an attribute selected. \nPlease select an attribute and try again.", "No Attribute Selected", JOptionPane.ERROR_MESSAGE);
}
}
Aggregations