use of com.ramussoft.pb.Row in project ramus by Vitaliy-Yakovchuk.
the class NewProjectDialog method showModal.
public void showModal(final Engine engine, final AccessRules accessRules, final GUIFramework framework) {
((Journaled) engine).setNoUndoPoint();
final Properties name_author = new DefaultProperties(new Property[] { new DefaultProperty(AUTOR, Property.TEXT_FIELD), new DefaultProperty(PROJECT_NAME, Property.TEXT_FIELD), new DefaultProperty(MODEL_NAME, Property.TEXT_FIELD) }, Factory.getString("name_author.Describe"));
final Properties used_at = new DefaultProperties(new Property[] { new DefaultProperty(USED_AT, Property.TEXT_FIELD) }, Factory.getString("used_at.Describe"));
final Properties def = new DefaultProperties(new Property[] { new DefaultProperty(DEFINITION, Property.TEXT) }, Factory.getString("describe.Describe"));
final Properties clasificators = new DefaultProperties(new Property[] { new DefaultProperty(CLASIFICATOR1, Property.TEXT_FIELD), new DefaultProperty(CLASIFICATOR2, Property.TEXT_FIELD), new DefaultProperty(CLASIFICATOR3, Property.TEXT_FIELD), new DefaultProperty(CLASIFICATOR4, Property.TEXT_FIELD), new DefaultProperty(CLASIFICATOR5, Property.TEXT_FIELD) }, Factory.getString("Clasificators.Describe"));
masterModel = new DefaultMasterModel(new Properties[] { name_author, used_at, def, clasificators });
mainPanel = new MainPanel(new PanelCreator(masterModel)) {
@Override
public boolean cancel() {
if (super.cancel()) {
NewProjectDialog.this.setVisible(false);
finish();
return true;
}
return false;
}
@Override
protected void finish() {
super.finish();
((Journaled) engine).startUserTransaction();
final Qualifier baseFunction = engine.createQualifier();
String modelName = getValue(MODEL_NAME);
if ((modelName == null) || (modelName.length() == 0))
baseFunction.setName(ResourceLoader.getString("base_function"));
else
baseFunction.setName(modelName);
Attribute name = engine.createAttribute(new AttributeType("Core", "Text", true));
name.setName(ResourceLoader.getString("name"));
engine.updateAttribute(name);
java.util.Properties ps = engine.getProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES);
ps.setProperty(AutochangePlugin.AUTO_ADD_ATTRIBUTE_IDS, Long.toString(name.getId()));
ps.setProperty(AutochangePlugin.ATTRIBUTE_FOR_NAME, Long.toString(name.getId()));
engine.setProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES, ps);
baseFunction.getAttributes().add(name);
baseFunction.setAttributeForName(name.getId());
IDEF0Plugin.installFunctionAttributes(baseFunction, engine);
Element element = engine.createElement(IDEF0Plugin.getModelTree(engine).getId());
engine.setAttribute(element, StandardAttributesPlugin.getAttributeQualifierId(engine), baseFunction.getId());
HierarchicalPersistent hp = new HierarchicalPersistent();
hp.setParentElementId(-1l);
hp.setPreviousElementId(-1l);
engine.setAttribute(element, StandardAttributesPlugin.getAttributeNameAttribute(engine), baseFunction.getName());
engine.setAttribute(element, StandardAttributesPlugin.getHierarchicalAttribute(engine), hp);
DataPlugin dataPlugin = NDataPluginFactory.getDataPlugin(baseFunction, engine, accessRules);
if (dfd.isSelected())
dataPlugin.getBaseFunction().setDecompositionType(MovingArea.DIAGRAM_TYPE_DFD);
else if (dfds.isSelected())
dataPlugin.getBaseFunction().setDecompositionType(MovingArea.DIAGRAM_TYPE_DFDS);
else if (dfds.isSelected())
dataPlugin.getBaseFunction().setDecompositionType(MovingArea.DIAGRAM_TYPE_DFDS);
ProjectOptions projectOptions = new ProjectOptions();
projectOptions.setProjectAutor(getValue(AUTOR));
projectOptions.setProjectName(getValue(PROJECT_NAME));
projectOptions.setDefinition(getValue(DEFINITION));
projectOptions.setUsedAt(getValue(USED_AT));
NewProjectDialog.this.setVisible(false);
final String[] cls = getClasifiactors();
final StringBuffer ounersIds = new StringBuffer();
for (final String c : cls) {
Row row = dataPlugin.createRow(null, false);
Qualifier qualifier = engine.getQualifier(StandardAttributesPlugin.getQualifierId(engine, row.getElement().getId()));
qualifier.setName(c);
engine.updateQualifier(qualifier);
if (ouners.indexOf(c) >= 0) {
ounersIds.append(qualifier.getId());
ounersIds.append(' ');
}
}
dataPlugin.setProperty(DataPlugin.PROPERTY_OUNERS, ounersIds.toString());
dataPlugin.getBaseFunction().setProjectOptions(projectOptions);
((Journaled) engine).commitUserTransaction();
((Journaled) engine).setNoUndoPoint();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
framework.propertyChanged("ShowWorkspace", "Workspace.IDEF0");
OpenDiagram open = new OpenDiagram(baseFunction, -1l);
framework.propertyChanged(IDEF0ViewPlugin.OPEN_DIAGRAM, open);
}
});
}
};
setContentPane(mainPanel);
pack();
Dimension size = this.getSize();
setMinimumSize(new Dimension(size.width, size.height + 30));
setLocationRelativeTo(null);
setVisible(true);
frame.repaint();
}
use of com.ramussoft.pb.Row in project ramus by Vitaliy-Yakovchuk.
the class HTMLHelper method getDiagram.
/*
*
* private static final int IMAGE_WIDTH = 850; private static final int
* IMAGE_HEIGHT = 738;
*/
public String getDiagram(final String sId, final String functionController, final String clasificatorController) {
if (sId == null)
return null;
final Row r = dataPlugin.findRowByGlobalId(GlobalId.convert(sId));
if (r instanceof Function) {
final Function function = (Function) r;
final int imageWidth = IMAGE_WIDTH;
final int imageHeight = IMAGE_HEIGHT;
final DiagramHolder htmlStream = new DiagramHolder();
htmlStream.println("<img border=0 width=" + imageWidth + " height=" + imageHeight + " src=\"" + functionController + "idef0/" + function.getGlobalId().toString() + "\" useMap=#M" + function.getGlobalId().toString() + ">");
htmlStream.println("<map name=M" + function.getGlobalId().toString() + ">");
final Vector childs = dataPlugin.getChilds(function, true);
final MovingArea area = PIDEF0painter.createMovingArea(new Dimension(imageWidth, imageHeight), dataPlugin);
final SectorRefactor refactor = area.getRefactor();
for (int i = 0; i < childs.size(); i++) {
final Function fun = (Function) childs.get(i);
String where;
if (fun.isLeaf())
where = clasificatorController;
else
where = functionController + "index/";
htmlStream.print("<area shape=RECT coords=" + getAreaCoords(fun.getBounds(), area) + " href=\"" + where + fun.getGlobalId().toString() + "\"");
htmlStream.println(">");
}
refactor.loadFromFunction(function, false);
final int sc = refactor.getSectorsCount();
for (int i = 0; i < sc; i++) {
final PaintSector sector = refactor.getSector(i);
final Stream stream = sector.getStream();
final MovingLabel text = refactor.getSector(i).getText();
if (text != null && stream != null) {
htmlStream.print("<area shape=RECT coords=" + getAreaCoords(text.getBounds(), area) + " href=\"" + clasificatorController + stream.getGlobalId().toString() + "\"");
htmlStream.println(">");
}
final int l = sector.getPinCount();
for (int j = 0; j < l; j++) if (stream != null) {
final Pin pin = sector.getPin(j);
htmlStream.print("<area shape=RECT coords=" + getPinCoords(pin, area) + " href=\"" + clasificatorController + stream.getGlobalId().toString() + "\"");
htmlStream.println(">");
}
}
htmlStream.println("<map>");
return htmlStream.toString();
}
return null;
}
use of com.ramussoft.pb.Row in project ramus by Vitaliy-Yakovchuk.
the class UserTemplate method createChilds.
public void createChilds(final Function function, final DataPlugin dataPlugin) {
Hashtable<Long, Long> trans = new Hashtable<Long, Long>();
final MovingArea ma = new MovingArea(dataPlugin);
ma.setDataPlugin(dataPlugin);
ma.setActiveFunction(function);
final SectorRefactor refactor = ma.getRefactor();
try {
final ByteArrayInputStream streamr = new ByteArrayInputStream(data);
final ObjectInputStream stream = new ObjectInputStream(streamr);
final MemoryData data = new MemoryData();
int l = DataLoader.readInteger(stream);
for (int i = 0; i < l; i++) {
final Function c = (Function) dataPlugin.createRow(function, true);
c.setName(functionNames.get(i));
if (i < functionTypes.size())
c.setType(functionTypes.get(i));
if (i < functionLinks.size()) {
Row r = dataPlugin.findRowByGlobalId(functionLinks.get(i));
if (r != null) {
if (r instanceof Stream) {
Stream st = (Stream) r;
Stream s = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
s.setAttachedStatus(st.getAttachedStatus());
s.setEmptyName(st.isEmptyName());
s.setRows(st.getAdded());
c.setLink(s.getElement().getId());
}
}
}
final long id = DataLoader.readLong(stream);
trans.put(id, c.getElement().getId());
c.setBounds(DataLoader.readFRectangle(stream));
c.setFont(DataLoader.readFont(stream, data));
c.setBackground(DataLoader.readColor(stream, data));
c.setForeground(DataLoader.readColor(stream, data));
}
// Read version of
final int ver = DataLoader.readInteger(stream);
// Paint
// Sector format
l = DataLoader.readInteger(stream);
HashMap<Sector, List<SectorPointPersistent>> pointsCache = new HashMap<Sector, List<SectorPointPersistent>>();
HashMap<Long, Long> pointIds = new HashMap<Long, Long>();
for (int i = 0; i < l; i++) {
final Sector s = dataPlugin.createSector();
s.setFunction(function);
final long id = DataLoader.readLong(stream);
trans.put(id, ((NSector) s).getElementId());
final byte[] va = DataLoader.readBytes(stream);
s.setVisualAttributes(va);
List<SectorPointPersistent> points = (List) stream.readObject();
pointsCache.put(s, points);
normalize(points, dataPlugin.getEngine(), pointIds);
s.setSectorPointPersistents(points);
s.setSectorProperties((SectorPropertiesPersistent) stream.readObject());
// final byte bs[] = DataLoader.readBytes(stream);
// final ByteArrayInputStream ba = new ByteArrayInputStream(bs);
final PaintSector ps = PaintSector.loadFromSector(ver, ma, data, dataPlugin, s);
refactor.addSector(ps);
Crosspoint c;
if (DataLoader.readBoolean(stream)) {
c = getCrosspoint(dataPlugin, trans, stream);
s.getStart().setCrosspointA(c);
}
loadBorder(s.getStart(), stream, trans, dataPlugin, refactor, ps, true);
s.getStart().commit();
if (DataLoader.readBoolean(stream)) {
c = getCrosspoint(dataPlugin, trans, stream);
s.getEnd().setCrosspointA(c);
}
loadBorder(s.getEnd(), stream, trans, dataPlugin, refactor, ps, false);
s.getEnd().commit();
if (DataLoader.readBoolean(stream)) {
int count = DataLoader.readInteger(stream);
List<Row> rows = new ArrayList<Row>();
for (int j = 0; j < count; j++) {
Row row = loadRow(stream, dataPlugin);
if (row != null)
rows.add(row);
}
if (rows.size() > 0) {
Stream stream2 = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
stream2.setRows(rows.toArray(new Row[rows.size()]));
((NSector) s).setThisStream(stream2);
}
}
}
setPoints(pointsCache);
refactor.saveToFunction();
} catch (final Exception e) {
e.printStackTrace();
}
}
use of com.ramussoft.pb.Row in project ramus by Vitaliy-Yakovchuk.
the class DFDSRoleOptionsDialog method onOk.
@Override
protected void onOk() {
if (!isCanOk()) {
JOptionPane.showMessageDialog(this, ResourceLoader.getString("you_should_enter_name_or_at_least_on_added_elemen"));
return;
}
if (!isOkStreamName()) {
if (JOptionPane.showConfirmDialog(this, ResourceLoader.getString("you_entered_exists_stream_continue"), ResourceLoader.getString("warning"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
return;
}
}
DFDSRole role = (DFDSRole) object;
Journaled journaled = (Journaled) dataPlugin.getEngine();
journaled.startUserTransaction();
Function function = object.getFunction();
function.setFont(fontChooser.getSelFont());
function.setBackground(backgroundColorChooser.getColor());
function.setForeground(foregroundColorChooser.getColor());
role.setAlternativeText(sectorNameEditor.getAlternativeTextField().getText());
Stream stream = sectorRowsEditor.getStream();
if (stream == null) {
stream = sectorNameEditor.findStreamByName();
if (stream == null) {
stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
}
}
final String t = sectorNameEditor.getArrowName();
if (!t.equals("")) {
if (!t.equals(stream.getName()) && sectorNameEditor.findStreamByName(stream.getName()) != null) {
stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
}
}
if (t.equals("")) {
if (!stream.isEmptyName()) {
stream = (Stream) dataPlugin.createRow(dataPlugin.getBaseStream(), true);
stream.setEmptyName(true);
}
} else {
stream.setName(t);
}
stream.setRows(sectorRowsEditor.getRows());
role.setStream(stream, ReplaceStreamType.SIMPLE);
// sector.setStreamAddedByRefactor(false);
final Row[] rs = sectorRowsEditor.getRows();
role.setRows(rs);
if (rs != null) {
RectangleVisualOptions ops = new RectangleVisualOptions();
ops.bounds = function.getBounds();
ops.background = function.getBackground();
ops.font = function.getFont();
ops.foreground = function.getForeground();
for (Row row : rs) if (row != null) {
IDEF0Plugin.setDefaultRectangleVisualOptions(dataPlugin.getEngine(), row.getElement(), ops);
}
}
journaled.commitUserTransaction();
setVisible(false);
}
use of com.ramussoft.pb.Row in project ramus by Vitaliy-Yakovchuk.
the class DFDSMovingLabel method getText.
@Override
public String getText() {
if (labelText == null) {
String s = sector.getAlternativeText();
if ("".equals(s)) {
final Stream stream = sector.getStream();
if (stream != null) {
if (stream.isEmptyName()) {
Row[] rows = stream.getAdded();
StringBuilder sb = null;
for (Row row : rows) if (row != null) {
if (sb == null)
sb = new StringBuilder(row.getName());
else {
sb.append(";\n");
sb.append(row.getName());
}
String status = row.getAttachedStatus();
if (status != null) {
int i = status.indexOf('|');
if (i >= 0) {
status = status.substring(i + 1);
if (status.trim().length() == 0)
status = null;
}
}
if (status != null) {
sb.append(" (");
sb.append(status);
sb.append(')');
}
}
if (sb != null)
s = sb.toString();
} else
s = stream.getName();
}
}
labelText = s;
}
return labelText;
}
Aggregations