use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class ModelsPanel method init.
private void init() {
tree = new RowTreeTableComponent(engine, IDEF0Plugin.getModelTree(engine), framework.getAccessRules(), new ModelRowCreator(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework) {
@Override
protected RowTreeTableModel createRowTreeTableModel(final Engine engine, Qualifier qualifier, AccessRules accessRules, RootCreater rootCreater, Attribute[] attributes, GUIFramework framework) {
RowTreeTableModel rowTreeTableModel = new RowTreeTableModel(engine, qualifier, attributes, accessRules, rootCreater, framework) {
@Override
protected RowNode newRowNode(Row row) {
Long id = (Long) row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine));
if (id != null) {
Qualifier qualifier = engine.getQualifier(id);
if (qualifier != null) {
ModelsNode node = newModelsNode(row, qualifier);
node.getTreeTableModel().setTable(tree.getTable());
node.getTreeTableModel().setModelSupport(tree.getModel().getModelSupport());
return node;
}
}
return super.newRowNode(row);
}
@Override
public boolean isCellEditable(Object node, int column) {
if (super.isCellEditable(node, column)) {
if (node instanceof ModelsNode)
return true;
}
return false;
}
};
return rowTreeTableModel;
}
@Override
protected RowTreeTable createTable(AccessRules accessRules, GUIFramework framework, AttributePlugin[] plugins) {
return new RowTreeTable(accessRules, model.getRowSet(), plugins, framework, model) {
long treeModelsId = IDEF0Plugin.getModelTree(engine).getId();
@Override
public Transferable createTransferable() {
final int[] is = getSelectedRows();
final ArrayList<Integer> al = new ArrayList<Integer>();
long id = IDEF0Plugin.getModelTree(engine).getId();
Rows rows = new Rows();
for (final int i : is) {
al.add(i);
TreeTableNode node = (TreeTableNode) getPathForRow(i).getLastPathComponent();
if ((node != null) && (node.getRow() != null)) {
Row row = node.getRow();
rows.add(row);
if (row.getElement().getQualifierId() != id)
return null;
}
}
exporting = true;
return new ArrayTransferable(al, rows);
}
@Override
public boolean importData(Transferable t, boolean on, int aIndex) {
int index = aIndex;
long id = IDEF0Plugin.getModelTree(engine).getId();
if (index >= getRowCount())
index--;
if (index < 0)
return false;
TreeTableNode node = (TreeTableNode) getPathForRow(index).getLastPathComponent();
if (node.getRow() != null)
if (node.getRow().getElement().getQualifierId() != id)
return false;
return super.importData(t, on, aIndex);
}
@Override
protected Icon getDefaultIcon(Row row) {
if (row.getElement().getQualifierId() != treeModelsId) {
if (row.getChildCount() == 0)
return note;
else
return function;
}
if (row.getAttribute(StandardAttributesPlugin.getAttributeQualifierId(engine)) == null)
return null;
return ModelsPanel.this.model;
}
};
}
};
fixTable((TreeTableNode) tree.getModel().getRoot());
tree.getTable().addMouseListener(new MouseAdapter() {
private int[] lastSelectedRows;
private long lastClickTime;
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
if ((e.getClickCount() % 2 == 0) && (e.getClickCount() > 0)) {
openDiagram();
} else {
if ((e.getClickCount() == 1) && (System.currentTimeMillis() - lastClickTime < QualifierView.EDIT_NAME_CLICK_DELAY) && (Arrays.equals(lastSelectedRows, tree.getTable().getSelectedRows()))) {
if (!tree.getTable().isEditing()) {
editTableField();
}
} else {
lastClickTime = System.currentTimeMillis();
lastSelectedRows = tree.getTable().getSelectedRows();
}
}
}
}
});
tree.getTable().setEditIfNullEvent(false);
tree.getTable().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "EditCell");
tree.getTable().getActionMap().put("EditCell", new AbstractAction() {
/**
*/
private static final long serialVersionUID = 3229634866196074563L;
@Override
public void actionPerformed(ActionEvent e) {
if ((tree.getTable().getSelectedRow() >= 0) && (tree.getTable().getSelectedColumn() >= 0))
editTableField();
}
});
JScrollPane pane = new JScrollPane();
pane.setViewportView(tree);
this.add(pane, BorderLayout.CENTER);
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class NDataPluginFactory method createDataPlugin.
private DataPlugin createDataPlugin() {
DataPlugin plugin = (DataPlugin) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { DataPlugin.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
String name = method.getName();
if ("getBaseFunction".equals(name)) {
if (rowBaseFunction == null) {
rowBaseFunction = getBaseFunction(dataPlugin, baseFunction);
}
return rowBaseFunction;
}
if ("getBaseFunctionQualifier".equals(name))
return baseFunction;
if ("isReadOnly".equals(name))
return !dataPlugin.getAccessRules().canUpdateQualifier(baseFunction.getId());
if ("createRow".equals(name)) {
com.ramussoft.pb.Row parent = (com.ramussoft.pb.Row) args[0];
RowSet set = dataPlugin.getRowSet(baseFunction.getId());
if (parent instanceof Function) {
Row row = set.createRow((Row) parent);
((NFunction) row).setDefaultValues();
((NFunction) row).setDecompositionType(((Function) parent).getDecompositionType());
return row;
}
} else if ("createFunction".equals(name)) {
com.ramussoft.pb.Function parent = (com.ramussoft.pb.Function) args[0];
final Integer type = (Integer) args[1];
RowSet set = dataPlugin.getRowSet(baseFunction.getId());
if (parent instanceof Function) {
Row row = set.createRow((Row) parent, new ElementCreationCallback() {
@Override
public void created(Element element) {
Engine engine = dataPlugin.getEngine();
Attribute attribute = IDEF0Plugin.getFunctionTypeAttribute(engine);
engine.setAttribute(element, attribute, type);
}
});
((NFunction) row).setDefaultValues();
((NFunction) row).setDecompositionType(((Function) parent).getDecompositionType());
return row;
}
} else if ((("getChilds".equals(name)) || ("getRecChilds".equals(name))) && (args[0] == null) && (((Boolean) args[1]) == false)) {
Vector v = (Vector) method.invoke(dataPlugin, args);
v.add(0, dataPlugin.getBaseStream());
v.add(0, getBaseFunction(dataPlugin, baseFunction));
return v;
}
if ("getProjectOptions".equals(name))
return getProjectOptions();
if ("setProjectOptions".equals(name))
return setProjectOptions((ProjectOptions) args[0]);
if ("refresh".equals(name)) {
fullRefrash((GUIFramework) args[0]);
return null;
}
return method.invoke(dataPlugin, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
private Row getBaseFunction(final NDataPlugin dataPlugin, final Qualifier baseFunction) {
return dataPlugin.getNBaseFunction(baseFunction.getId());
}
protected Object setProjectOptions(ProjectOptions projectOptions) {
getBaseFunction(dataPlugin, baseFunction).setAttribute(IDEF0Plugin.getProjectPreferencesAttrtibute(dataPlugin.getEngine()), projectOptions);
return null;
}
protected Object getProjectOptions() {
return getBaseFunction(dataPlugin, baseFunction).getAttribute(IDEF0Plugin.getProjectPreferencesAttrtibute(dataPlugin.getEngine()));
}
});
plugin.getBaseFunction();
return plugin;
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class ModelParaleler method copyAttributes.
private void copyAttributes(List<Attribute> attributes, Element source, Element destination) {
for (Attribute attribute : attributes) if ((!attribute.getAttributeType().getTypeName().equals("Hierarchical")) && (!attribute.getAttributeType().getTypeName().equals("VisualData")) && (!attribute.getAttributeType().getTypeName().equals("SectorBorder"))) {
AttributePlugin plugin = attribute.getAttributeType().getAttributePlugin(fromEngine);
if (plugin == null)
System.err.println("WARNING: Attribute plugin not found for type: " + attribute.getAttributeType());
else
plugin.copyAttribute(fromEngine, toEngine, attribute, getAttribute(attribute), source, destination, this);
}
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class ModelParaleler method loadFromParalel.
public void loadFromParalel(Function base, boolean importAll, List<Qualifier> selected) {
this.base = base;
List<Attribute> tAttrs = toEngine.getAttributes();
List<Attribute> fAttrs = fromEngine.getAttributes();
for (Attribute f : fAttrs) for (Attribute t : tAttrs) if ((f.getName().equals(t.getName())) && (f.getAttributeType().equals(t.getAttributeType())))
attrHash.put(f.getId(), t);
List<Qualifier> fList = fromEngine.getQualifiers();
List<Qualifier> tList = toEngine.getQualifiers();
for (Qualifier f : fList) if (!IDEF0Plugin.isFunction(f))
for (Qualifier t : tList) if (!IDEF0Plugin.isFunction(t))
if (f.getName().equals(t.getName()))
qHash.put(f.getId(), t);
Vector<Row> fRows = fromDataPlugin.getRecChilds(null, false);
Vector<Row> tRows = toDataPlugin.getRecChilds(null, false);
for (Row f : fRows) {
for (Row t : tRows) {
if (f.getName().equals(t.getName())) {
rowHash.put(f.getElement().getId(), t);
Vector<Row> fCRows = fromDataPlugin.getRecChilds(f, true);
Vector<Row> tCRows = toDataPlugin.getRecChilds(t, true);
for (Row fc : fCRows) for (Row tc : tCRows) if (fc.getName().equals(tc.getName()))
rowHash.put(fc.getElement().getId(), tc);
}
}
}
if (importAll)
createAllRows();
for (Qualifier qualifier : selected) {
fromDataPlugin = NDataPluginFactory.getDataPlugin(qualifier, fromEngine, fromDataPlugin.getAccessRules());
List<Attribute> list = getAttributes(qualifier.getAttributes());
Qualifier baseFunction = toEngine.getQualifier(base.getElement().getQualifierId());
for (Attribute a : list) if (baseFunction.getAttributes().indexOf(a) < 0)
baseFunction.getAttributes().add(a);
toEngine.updateQualifier(baseFunction);
int r;
if ((r = fromDataPlugin.getBaseFunction().getChildCount()) > 0)
for (int i = 0; i < r; i++) {
function = (Function) fromDataPlugin.getBaseFunction().getChildAt(i);
Vector<Row> childs = fromDataPlugin.getRecChilds(function, true);
childs.add(0, function);
for (Row row : childs) {
NFunction dest = (NFunction) getRow(row);
showMessageAnimation(dest.toString());
}
NFunction func = (NFunction) getRow(function);
createSectorsOnUpperLevel(func);
}
}
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class ModelParaleler method init.
@SuppressWarnings("deprecation")
private void init() {
Vector<Row> v = fromDataPlugin.getRecChilds(null, false);
for (Row r : v) {
long qualifierId = StandardAttributesPlugin.getQualifierId(fromEngine, r.getElement());
rowForQualifiers.put(qualifierId, r);
}
Qualifier bs = IDEF0Plugin.getBaseStreamQualifier(fromEngine);
rowForQualifiers.put(bs.getId(), fromDataPlugin.getBaseStream());
List<Attribute> attrs = fromEngine.getSystemAttributes();
List<Attribute> dAttrs = toEngine.getSystemAttributes();
Hashtable<String, Attribute> hash = new Hashtable<String, Attribute>();
for (Attribute attribute : dAttrs) hash.put(attribute.getName(), attribute);
for (Attribute a : attrs) {
Attribute d = hash.get(a.getName());
if (d == null)
System.err.println("WARNING: System attribute not found in destination engine: " + a.getName() + " type: " + a.getAttributeType());
else
attrHash.put(a.getId(), d);
}
}
Aggregations