use of com.ramussoft.common.AccessRules 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.AccessRules 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);
}
}
};
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class ElistTabView method createComponent.
@Override
public JComponent createComponent() {
final Engine engine = framework.getEngine();
AccessRules rules = framework.getAccessRules();
ElementListPropertyPersistent p = (ElementListPropertyPersistent) engine.getAttribute(null, elementList);
boolean addListener = q1 == null;
q1 = engine.getQualifier(p.getQualifier1());
q2 = engine.getQualifier(p.getQualifier2());
readOnly = !((rules.canUpdateAttribute(q1.getId(), elementList.getId())) && (rules.canUpdateAttribute(q2.getId(), elementList.getId())));
if (addListener) {
engine.addElementAttributeListener(q1, leftAttributeListener);
engine.addElementAttributeListener(q2, rightAttributeListener);
}
left = new ElistPanel(framework, engine, rules, q1, elementList) {
@Override
public String getPropertiesPrefix() {
return "left" + elementList.getId();
}
@Override
public void changeSelection(SelectionEvent event) {
ElistTabView.this.changeSelection(this, event);
}
@Override
public JComponent createComponent() {
unique = null;
if (getComponent() != null) {
left.clearSelection();
left.setSelectType(SelectType.RADIO);
right.clearSelection();
right.setSelectType(SelectType.RADIO);
}
JComponent component2 = super.createComponent();
getComponent().getPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
comp.repaint();
}
});
getComponent().getTable().getModel().addTableModelListener(modelListener);
getComponent().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@SuppressWarnings("unchecked")
@Override
public void valueChanged(ListSelectionEvent e) {
TreeTableNode node = left.getComponent().getTable().getSelectedNode();
if ((node != null) && (node.getRow() != null)) {
leftElement = node.getRow().getElement();
leftValue = (List<ElementListPersistent>) engine.getAttribute(leftElement, elementList);
if (unique == null)
rightValue = null;
} else
leftValue = null;
comp.repaint();
}
});
return component2;
}
@Override
public void setSelectType(SelectType selectType) {
if ((!readOnly) || (selectType.equals(SelectType.NONE)))
super.setSelectType(selectType);
}
};
right = new ElistPanel(framework, engine, rules, q2, elementList) {
@Override
public String getPropertiesPrefix() {
return "right" + elementList.getId();
}
@Override
public void changeSelection(SelectionEvent event) {
ElistTabView.this.changeSelection(this, event);
}
@Override
public JComponent createComponent() {
unique = null;
if (getComponent() != null) {
left.clearSelection();
left.setSelectType(SelectType.RADIO);
right.clearSelection();
right.setSelectType(SelectType.RADIO);
}
JComponent component2 = super.createComponent();
getComponent().getPane().getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
comp.repaint();
}
});
getComponent().getTable().getModel().addTableModelListener(modelListener);
getComponent().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@SuppressWarnings("unchecked")
@Override
public void valueChanged(ListSelectionEvent e) {
TreeTableNode node = right.getComponent().getTable().getSelectedNode();
if ((node != null) && (node.getRow() != null)) {
rightElement = node.getRow().getElement();
rightValue = (List<ElementListPersistent>) engine.getAttribute(rightElement, elementList);
if (unique == null)
leftValue = null;
} else
rightValue = null;
comp.repaint();
}
});
return component2;
}
@Override
public void setSelectType(SelectType selectType) {
if ((!readOnly) || (selectType.equals(SelectType.NONE)))
super.setSelectType(selectType);
}
};
JSplitPane pane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
pane1.setRightComponent(rightContainer);
comp.setBackground(Color.white);
pane1.setLeftComponent(comp);
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
pane.setLeftComponent(leftContainer);
Properties properties = engine.getProperties(getProperiesName());
revert = Options.getBoolean("REVERT", false, properties);
revertAction.putValue(Action.SELECTED_KEY, revert);
addPanels();
JPanel panel = new JPanel(new BorderLayout());
panel.add(pane1, BorderLayout.CENTER);
pane.setRightComponent(panel);
component = new JPanel(new BorderLayout());
component.add(pane, BorderLayout.CENTER);
Options.loadOptions(component, properties);
if (readOnly) {
left.setSelectType(SelectType.NONE);
right.setSelectType(SelectType.NONE);
}
return component;
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class EngineFactory method createJournaledEngine.
public Engine createJournaledEngine(DirectoryJournalFactory journalFactory) {
try {
JDBCTemplate template = new JDBCTemplate(createNewConnectionA());
suits = new ArrayList<PluginProvider>();
suits.add(new SimpleAttributePluginSuit());
suits.add(new IDEF0PluginProvider());
Properties ps = getPropeties();
if (ps != null) {
String suitNames = ps.getProperty("AdditionalSuits");
if (suitNames != null)
PluginFactory.loadAdditionalSuits(suitNames, suits);
canUndoRedo = !"false".equals(ps.getProperty("CanUndoRedo"));
}
suits.addAll(getAdditionalSuits());
createUniversalPersistentFactory(template, (ps == null) ? null : ps.getProperty("PersistentPluginsProvider"));
factory = createPluginFactory(suits);
String prefix = "ramus_";
impl = new ServerIEngineImpl(0, template, prefix, factory);
accessor = impl.getAccessor();
persistentFactory = new PersistentFactory(prefix, factory.getAttributePlugins(), template);
persistentFactory.rebuild();
checkIfGroupsExists();
Engine result;
Journaled journaled;
if (cachedData == null) {
JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
result = journaledEngine2;
journaled = journaledEngine2.getJournal();
} else {
JournaledEngine engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {
@Override
protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
}
};
journaled = engine.getJournal();
CachedEngine cachedEngine = new CachedEngine(engine, cachedData);
for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
result = cachedEngine;
}
EngineLogExtension engineLogExtension = new EngineLogExtension(result, journaled);
log = new Log(result, journaled) {
protected Event createEvent(String type, UpdateEventCallback callback) {
String user = "admin";
if (impl.getServerAccessRules() != null)
user = impl.getServerAccessRules().getUser().getLogin();
long id = impl.nextValue("qualifiers_log_seq");
return callback.createEvent(this, id, new Timestamp(System.currentTimeMillis()), type, user, null);
}
};
log.addExtension(engineLogExtension);
log.addExtension(new StorageLogExtension(new JDBCTemplate(createNewConnection()), prefix));
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class XMLComponentFramefork method createLabalComponentFactory.
private ComponentFactory createLabalComponentFactory() {
return new AbstractComponentFactory() {
@Override
public String getType() {
return "Label";
}
@Override
public Component createComponent(Diagram diagram, Engine engine, AccessRules accessRules, Bounds bounds) {
Label label = new Label();
label.setWidth(((XMLDiagram) diagram).getWidthForCompontns());
return label;
}
@Override
public Component getComponent(Engine engine, AccessRules accessRules, Bounds bounds) {
return null;
}
};
}
Aggregations