use of com.ramussoft.pb.DataPlugin in project ramus by Vitaliy-Yakovchuk.
the class IDEF0ViewPlugin method getActionDescriptors.
@SuppressWarnings("unused")
@Override
public ActionDescriptor[] getActionDescriptors() {
ActionDescriptor openStreans = new ActionDescriptor();
openStreans.setActionLevel(ActionLevel.GLOBAL);
openStreans.setMenu("Tools");
openStreans.setAction(new AbstractAction() {
{
putValue(ACTION_COMMAND_KEY, "streams");
}
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
framework.propertyChanged(OPEN_STREAMS);
}
});
ActionDescriptor runWebServer = new ActionDescriptor();
runWebServer.setActionLevel(ActionLevel.GLOBAL);
runWebServer.setMenu("Tools");
runWebServer.setAction(new AbstractAction() {
{
putValue(ACTION_COMMAND_KEY, MainFrame.OPEN_WEB_SERVER);
}
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if (server == null) {
server = new HTTPServer("0", NDataPluginFactory.getDataPlugin(null, engine, rules), framework) {
@Override
protected void serverStarted() {
AbstractAttributePlugin.openUrl("http://127.0.0.1:" + getServer().getLocalPort(), framework);
}
};
} else {
AbstractAttributePlugin.openUrl("http://127.0.0.1:" + server.getServer().getLocalPort(), framework);
}
}
});
ActionDescriptor idef0Separator = new ActionDescriptor();
idef0Separator.setMenu("IDEF0");
ActionDescriptor loadModelsFromFile = new ActionDescriptor();
loadModelsFromFile.setActionLevel(ActionLevel.GLOBAL);
loadModelsFromFile.setMenu("IDEF0");
loadModelsFromFile.setAction(new AbstractAction() {
{
putValue(ACTION_COMMAND_KEY, "loadModelsFromFile");
}
@Override
public void actionPerformed(java.awt.event.ActionEvent event) {
DataPlugin plugin = NDataPluginFactory.getDataPlugin(null, engine, rules);
try {
final JFileChooser chooser = frame.getChooser();
if (chooser.showOpenDialog(framework.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
plugin.loadFromParalel(chooser.getSelectedFile(), framework);
}
} catch (final IOException e) {
JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
}
}
});
ActionDescriptor toolsSeparator = new ActionDescriptor();
toolsSeparator.setMenu("Tools");
if ((Metadata.DEMO) && (!new SerialCheker().check(Options.getString("SERIAL")))) {
Metadata.DEMO_REGISTERED = false;
if (Metadata.DEMO) {
framework.addActionListener("MainFrameShown", new ActionListener() {
@Override
public void onAction(ActionEvent event) {
String title = framework.getMainFrame().getTitle();
if (!Metadata.DEMO_REGISTERED)
title += " " + GlobalResourcesManager.getString("UnregisteredCopy");
else
title += " " + MessageFormat.format(GlobalResourcesManager.getString("RegisteredName"), Metadata.REGISTERED_FOR);
framework.getMainFrame().setTitle(title);
}
});
}
return new ActionDescriptor[] { runWebServer, openStreans, findAction(CURSOR_TOOL), findAction(FUNCTION_TOOL), findAction(ARROW_TOOL), findAction(TILDA_TOOL), findAction(TEXT_TOOL), findAction(EXTERNAL_REFERENCE_TOOL), findAction(DFDS_ROLE_TOOL), findAction(DATA_STORE_TOOL), findAction(IDEF0_NET), findAction(GO_TO_PARENT), findAction(GO_TO_CHILD), idef0Separator, findAction(CENTER_ALL_SECTORS), idef0Separator, loadModelsFromFile, toolsSeparator, findAction(ADD_MODEL_TO_TEMPLATE, "Tools"), findAction(USER_TEMPLATES, "Tools"), idef0Separator, findAction(MODEL_PROPETIES), findAction(DIAGRAM_PROPETIES), idef0Separator, findAction(EXPORT_TO_IMAGES), createExportToIDL(), createImportFromIDL(), createRegisterAction(), toolsSeparator, findAction(CREATE_LEVEL) };
} else {
if (Metadata.DEMO) {
framework.addActionListener("MainFrameShown", new ActionListener() {
@Override
public void onAction(ActionEvent event) {
String title = framework.getMainFrame().getTitle();
if (!Metadata.DEMO_REGISTERED)
title += " " + GlobalResourcesManager.getString("UnregisteredCopy");
else
title += " " + MessageFormat.format(GlobalResourcesManager.getString("RegisteredName"), Metadata.REGISTERED_FOR);
framework.getMainFrame().setTitle(title);
}
});
}
ActionDescriptor editSeparator = new ActionDescriptor();
editSeparator.setMenu("Edit");
ActionDescriptor cut = new ActionDescriptor();
cut.setMenu("Edit");
cut.setAction(frame.findAction(MainFrame.CUT));
ActionDescriptor copy = new ActionDescriptor();
copy.setMenu("Edit");
copy.setAction(frame.findAction(MainFrame.COPY));
ActionDescriptor paste = new ActionDescriptor();
paste.setMenu("Edit");
paste.setAction(frame.findAction(MainFrame.PASTE));
return new ActionDescriptor[] { runWebServer, openStreans, findAction(CURSOR_TOOL), findAction(FUNCTION_TOOL), findAction(ARROW_TOOL), findAction(TILDA_TOOL), findAction(TEXT_TOOL), findAction(EXTERNAL_REFERENCE_TOOL), findAction(DFDS_ROLE_TOOL), findAction(DATA_STORE_TOOL), findAction(IDEF0_NET), findAction(GO_TO_PARENT), findAction(GO_TO_CHILD), idef0Separator, findAction(CENTER_ALL_SECTORS), idef0Separator, loadModelsFromFile, toolsSeparator, findAction(ADD_MODEL_TO_TEMPLATE, "Tools"), findAction(USER_TEMPLATES, "Tools"), idef0Separator, findAction(MODEL_PROPETIES), findAction(DIAGRAM_PROPETIES), idef0Separator, findAction(EXPORT_TO_IMAGES), createExportToIDL(), createImportFromIDL(), editSeparator, cut, copy, paste };
}
}
use of com.ramussoft.pb.DataPlugin in project ramus by Vitaliy-Yakovchuk.
the class IDEF0ViewPlugin method getProjectPreferences.
@Override
public Preferences[] getProjectPreferences() {
List<Qualifier> list = IDEF0Plugin.getBaseQualifiers(engine);
Preferences[] res = new Preferences[((list.size() > 0) ? 1 : 0)];
final DataPlugin dataPlugin;
if (list.size() == 0)
dataPlugin = null;
else
dataPlugin = NDataPluginFactory.getDataPlugin(list.get(0), engine, rules);
if (res.length > 0)
res[res.length - 1] = new AbstractPreferences() {
private OwnerClasificators c = new OwnerClasificators(dataPlugin);
{
c.updateOuners();
}
@Override
public JComponent createComponent() {
return c;
}
@Override
public String getTitle() {
return ResourceLoader.getString("Owners.Clasificators");
}
@Override
public boolean save(JDialog dialog) {
c.apply();
return true;
}
};
return res;
}
use of com.ramussoft.pb.DataPlugin 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.pb.DataPlugin in project ramus by Vitaliy-Yakovchuk.
the class SectorCorrector method run.
public void run(Engine engine, AccessRules accessRules) {
((Journaled) engine).startUserTransaction();
log("Loading data");
List<Qualifier> list = IDEF0Plugin.getBaseQualifiers(engine);
for (Qualifier q : list) {
DataPlugin dataPlugin = NDataPluginFactory.getDataPlugin(q, engine, accessRules);
Vector<Row> v = dataPlugin.getRecChilds(dataPlugin.getBaseFunction(), true);
for (Row r : v) {
if (r.getChildCount() == 0) {
Function function = (Function) r;
MovingArea area = new MovingArea(dataPlugin, function);
area.setDataPlugin(dataPlugin);
SectorRefactor sr = area.getRefactor();
sr.loadFromFunction(function, false);
while (sr.getSectorsCount() > 0) {
sr.getSector(0).remove();
}
sr.saveToFunction();
log("Function " + r + " clean");
}
}
for (Row r : v) {
if (r.getChildCount() != 0) {
Function function = (Function) r;
MovingArea area = new MovingArea(dataPlugin, function);
area.setDataPlugin(dataPlugin);
SectorRefactor sr = area.getRefactor();
sr.loadFromFunction(function, false);
for (int i = 0; i < sr.getSectorsCount(); i++) {
PaintSector ps = sr.getSector(i);
if ((ps.getSector().getStart().getFunction() != null) && (ps.getSector().getStart().getFunction().getChildCount() == 0))
sr.createSectorOnIn(ps, true);
if ((ps.getSector().getEnd().getFunction() != null) && (ps.getSector().getEnd().getFunction().getChildCount() == 0))
sr.createSectorOnIn(ps, false);
}
log("Function " + r + " done");
}
}
}
((Journaled) engine).commitUserTransaction();
}
use of com.ramussoft.pb.DataPlugin in project ramus by Vitaliy-Yakovchuk.
the class IDEF0ViewPlugin method exportToIdl.
protected void exportToIdl() {
final JList list = new JList();
final List<Qualifier> base = IDEF0Plugin.getBaseQualifiers(engine);
Collections.sort(base, new Comparator<Qualifier>() {
private Collator collator = Collator.getInstance();
@Override
public int compare(Qualifier o1, Qualifier o2) {
return collator.compare(o1.getName(), o2.getName());
}
});
list.setModel(new AbstractListModel() {
@Override
public Object getElementAt(int index) {
return base.get(index);
}
@Override
public int getSize() {
return base.size();
}
});
JScrollPane pane = new JScrollPane();
pane.setViewportView(list);
JFileChooser fc = new JFileChooser() {
@Override
public void approveSelection() {
Qualifier result = (Qualifier) list.getSelectedValue();
if (result == null) {
JOptionPane.showMessageDialog(this, ResourceLoader.getString("select_model_first"));
} else {
File file = getSelectedFile();
if (file.exists()) {
if (JOptionPane.showConfirmDialog(framework.getMainFrame(), GlobalResourcesManager.getString("File.Exists"), UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
}
DataPlugin plugin = NDataPluginFactory.getDataPlugin(result, engine, rules);
try {
if (!file.getName().toLowerCase().endsWith(".idl")) {
file = new File(file.getParentFile(), file.getName() + ".idl");
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
plugin.exportToIDL(plugin.getBaseFunction(), fileOutputStream, "cp1251");
fileOutputStream.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(framework.getMainFrame(), e.getLocalizedMessage());
}
super.approveSelection();
}
}
};
fc.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isFile()) {
if (f.getName().toLowerCase().endsWith(".idl"))
return true;
return false;
}
return true;
}
@Override
public String getDescription() {
return "*.idl";
}
});
JPanel bottom = new JPanel(new TableLayout(new double[][] { { 5, TableLayout.FILL }, { TableLayout.MINIMUM, 5, TableLayout.FILL } }));
bottom.add(new JLabel(ResourceLoader.getString("Model")), "1, 0");
bottom.add(pane, "1, 2");
fc.setAccessory(bottom);
fc.showSaveDialog(framework.getMainFrame());
}
Aggregations