use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class ChartSetsView method createComponent.
@Override
public JComponent createComponent() {
Engine engine = framework.getEngine();
AccessRules accessRules = framework.getAccessRules();
component = new RowTreeTableComponent(engine, ChartPlugin.getChartSets(engine), accessRules, new RowRootCreater(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework);
table = component.getTable();
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
if ((e.getClickCount() % 2 == 0) && (e.getClickCount() > 0)) {
openChartSet();
} else {
if ((e.getClickCount() == 1) && (System.currentTimeMillis() - lastClickTime < EDIT_NAME_CLICK_DELAY) && (Arrays.equals(lastSelectedRows, table.getSelectedRows()))) {
if (!table.isEditing()) {
editTableField();
}
} else {
lastClickTime = System.currentTimeMillis();
lastSelectedRows = table.getSelectedRows();
}
}
}
}
});
table.addSelectionListener(new SelectionListener() {
@Override
public void changeSelection(SelectionEvent event) {
TreeTableNode selectedNode = component.getTable().getSelectedNode();
if (selectedNode == null)
openChartSetAction.setEnabled(false);
else {
Row row = selectedNode.getRow();
openChartSetAction.setEnabled(row != null);
}
deleteChartSetAction.setEnabled(openChartSetAction.isEnabled());
}
});
table.setEditIfNullEvent(false);
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "EditCell");
table.getActionMap().put("EditCell", new AbstractAction() {
/**
*/
private static final long serialVersionUID = 3229634866196074563L;
@Override
public void actionPerformed(ActionEvent e) {
if ((table.getSelectedRow() >= 0) && (table.getSelectedColumn() >= 0))
editTableField();
}
});
return component;
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class ChartSetsView method deleteDiagram.
public void deleteDiagram() {
List<Row> rows = new ArrayList<Row>();
int[] sels = table.getSelectedRows();
for (int i : sels) {
TreePath path = table.getPathForRow(i);
if (path != null) {
TreeTableNode node = (TreeTableNode) path.getLastPathComponent();
if (node != null) {
Row row = node.getRow();
if (row != null)
rows.add(row);
}
}
}
if (rows.size() > 0) {
if (JOptionPane.showConfirmDialog(component, GlobalResourcesManager.getString("DeleteActiveElementsDialog.Warning"), GlobalResourcesManager.getString("ConfirmMessage.Title"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
Engine engine = framework.getEngine();
((Journaled) engine).startUserTransaction();
for (Row row : rows) engine.deleteElement(row.getElementId());
((Journaled) engine).commitUserTransaction();
}
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class ChartSetsView method deleteChartSet.
public void deleteChartSet() {
List<Row> rows = new ArrayList<Row>();
int[] sels = table.getSelectedRows();
for (int i : sels) {
TreePath path = table.getPathForRow(i);
if (path != null) {
TreeTableNode node = (TreeTableNode) path.getLastPathComponent();
if (node != null) {
Row row = node.getRow();
if (row != null)
rows.add(row);
}
}
}
if (rows.size() > 0) {
if (JOptionPane.showConfirmDialog(component, GlobalResourcesManager.getString("DeleteActiveElementsDialog.Warning"), GlobalResourcesManager.getString("ConfirmMessage.Title"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
Engine engine = framework.getEngine();
((Journaled) engine).startUserTransaction();
for (Row row : rows) ChartPlugin.deleteChartSet(engine, row.getElement());
((Journaled) engine).commitUserTransaction();
}
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class ChartPreferencesDialog method onOk.
@Override
protected void onOk() {
Engine engine = framework.getEngine();
try {
((Journaled) engine).startUserTransaction();
chart.setName(name.getText());
Element element = chart.getElement();
editor.save(element);
((Journaled) engine).commitUserTransaction();
} catch (Exception e) {
((Journaled) engine).rollbackUserTransaction();
e.printStackTrace();
JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
}
super.onOk();
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class OtherElementPlugin method getAttributePreferenciesEditor.
@Override
public AttributePreferenciesEditor getAttributePreferenciesEditor() {
return new AttributePreferenciesEditor() {
private JComboBox qualifierBox = new JComboBox();
private JComboBox attributeBox = new JComboBox();
@Override
public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
OtherElementPropertyPersistent p = new OtherElementPropertyPersistent();
p.setQualifier(((Qualifier) qualifierBox.getSelectedItem()).getId());
p.setQualifierAttribute(((Attribute) attributeBox.getSelectedItem()).getId());
engine.setAttribute(null, attribute, p);
}
@Override
public boolean canApply() {
return (qualifierBox.getSelectedItem() != null) && (attributeBox.getSelectedItem() != null);
}
@Override
public JComponent createComponent(Attribute attribute, Engine engine, AccessRules accessRules) {
double[][] size = { { 5, TableLayout.FILL, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5, TableLayout.MINIMUM, 5 } };
JPanel panel = new JPanel(new TableLayout(size));
panel.add(new JLabel(GlobalResourcesManager.getString("OtherElement.Qualifier")), "1, 1");
panel.add(new JLabel(GlobalResourcesManager.getString("OtherElement.Attribute")), "3, 1");
for (Qualifier qualifier : engine.getQualifiers()) {
qualifierBox.addItem(qualifier);
}
if (attribute != null) {
OtherElementPropertyPersistent p = (OtherElementPropertyPersistent) engine.getAttribute(null, attribute);
qualifierBox.setSelectedItem(engine.getQualifier(p.getQualifier()));
long attributeId = p.getQualifierAttribute();
if (attributeId >= 0)
attributeBox.setSelectedItem(engine.getAttribute(attributeId));
qualifierBox.setEnabled(false);
}
qualifierBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
loadAttributes();
}
}
});
loadAttributes();
panel.add(qualifierBox, "1, 3");
panel.add(attributeBox, "3, 3");
return panel;
}
private void loadAttributes() {
attributeBox.removeAllItems();
Qualifier qualifier = (Qualifier) qualifierBox.getSelectedItem();
if (qualifier == null)
return;
for (Attribute attribute : qualifier.getAttributes()) {
attributeBox.addItem(attribute);
}
}
};
}
Aggregations