Search in sources :

Example 46 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class StreamAttributePlugin method getAttributeEditor.

@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor old) {
    if (old != null)
        old.close();
    return new AbstractAttributeEditor() {

        private SectorRowsEditor sectorRowsEditor;

        private SectorNameEditor sectorNameEditor;

        private PaintSector.Pin pin;

        private DataPlugin dataPlugin;

        private PaintSector sector;

        private JTabbedPane component;

        {
            dataPlugin = NDataPluginFactory.getDataPlugin(null, engine, rules);
            Sector sector = dataPlugin.findSectorByGlobalId(GlobalId.create(element.getId()));
            if (sector != null) {
                dataPlugin = NDataPluginFactory.getDataPlugin(engine.getQualifier(sector.getFunction().getElement().getQualifierId()), engine, rules);
                component = new JTabbedPane();
                sectorRowsEditor = new SectorRowsEditor(dataPlugin, framework, rules);
                sectorNameEditor = new SectorNameEditor(dataPlugin, framework, rules) {

                    @Override
                    public Stream getStream() {
                        return sectorRowsEditor.getStream();
                    }
                };
                sectorRowsEditor.setSectorNameEditor(sectorNameEditor);
                component.addTab(ResourceLoader.getString("stream"), null, sectorRowsEditor, null);
                component.addTab(ResourceLoader.getString("name"), null, sectorNameEditor, null);
                ResourceLoader.setJComponentsText(sectorRowsEditor);
                ResourceLoader.setJComponentsText(sectorNameEditor);
            }
        }

        @Override
        public Object setValue(Object value) {
            this.pin = (PaintSector.Pin) value;
            sector = pin.getSector();
            sectorNameEditor.setSector(sector.getSector());
            sectorRowsEditor.setSector(sector.getSector());
            return value;
        }

        @Override
        public Object getValue() {
            return pin;
        }

        @Override
        public JComponent getComponent() {
            if (component == null)
                return new JPanel();
            return component;
        }

        @Override
        public JComponent getLastComponent() {
            return component;
        }

        @Override
        public void apply(Engine engine, Element element, Attribute attribute, Object value) {
            sector.setShowText(sectorNameEditor.getBox().isSelected());
            sector.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);
            final Row[] added = stream.getAdded();
            stream.setRows(sectorRowsEditor.getRows());
            sector.setStream(stream, sectorNameEditor.getReplaceStreamType());
            stream = sector.getStream();
            stream.setRows(added);
            // sector.setStreamAddedByRefactor(false);
            final Row[] rs = sectorRowsEditor.getRows();
            sector.setRows(rs);
            sector.createTexts();
            PaintSector.save(sector, new DataLoader.MemoryData(), engine);
            sector.getMovingArea().getRefactor().setUndoPoint();
            sectorNameEditor.setChanged(false);
        }

        @Override
        public boolean canApply() {
            final boolean b = isSave();
            if (b) {
                if (!isOkStreamName()) {
                    if (JOptionPane.showConfirmDialog(component, ResourceLoader.getString("you_entered_exists_stream_continue"), ResourceLoader.getString("warning"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
                        return false;
                }
            } else {
                JOptionPane.showMessageDialog(component, ResourceLoader.getString("you_should_enter_name_or_at_least_on_added_elemen"));
                return false;
            }
            return b;
        }

        private boolean isSave() {
            final Row[] rs = sectorRowsEditor.getRows();
            final boolean b = rs.length > 0 || !sectorNameEditor.getArrowName().equals("");
            return b;
        }

        private boolean isOkStreamName() {
            final Stream stream = sectorNameEditor.findStreamByName();
            if (stream != null)
                return stream.equals(sectorNameEditor.getNullStream());
            return true;
        }

        @Override
        public boolean isSaveAnyway() {
            return sectorRowsEditor.isChanged() || sectorNameEditor.isChanged();
        }

        @Override
        public void close() {
            super.close();
            sectorRowsEditor.dispose();
        }
    };
}
Also used : JPanel(javax.swing.JPanel) Attribute(com.ramussoft.common.Attribute) Sector(com.ramussoft.pb.Sector) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) JTabbedPane(javax.swing.JTabbedPane) Element(com.ramussoft.common.Element) SectorNameEditor(com.ramussoft.pb.idef.frames.SectorNameEditor) DataLoader(com.dsoft.utils.DataLoader) AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) SectorRowsEditor(com.ramussoft.pb.idef.frames.SectorRowsEditor) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Stream(com.ramussoft.pb.Stream) Row(com.ramussoft.pb.Row) DataPlugin(com.ramussoft.pb.DataPlugin) Engine(com.ramussoft.common.Engine)

Example 47 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class LineStyleAttributePlugin method getAttributeEditor.

@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor old) {
    if (old != null)
        old.close();
    return new AbstractAttributeEditor() {

        private PaintSector.Pin pin;

        private LineStyleChooser component;

        private Stroke stroke;

        {
            component = new LineStyleChooser();
        }

        @Override
        public Object setValue(Object value) {
            this.pin = (PaintSector.Pin) value;
            stroke = pin.getSector().getStroke();
            component.setStroke(stroke);
            return value;
        }

        @Override
        public Object getValue() {
            return pin;
        }

        @Override
        public void apply(Engine engine, Element element, Attribute attribute, Object value) {
            LineStyleAttributePlugin.this.apply(component.getStroke(), pin);
        }

        @Override
        public JComponent getComponent() {
            return component;
        }

        @Override
        public boolean isSaveAnyway() {
            return !stroke.equals(component.getStroke());
        }
    };
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) Pin(com.ramussoft.pb.idef.elements.PaintSector.Pin) LineStyleChooser(com.ramussoft.pb.frames.components.LineStyleChooser) PaintSector(com.ramussoft.pb.idef.elements.PaintSector) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Engine(com.ramussoft.common.Engine)

Example 48 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class ElementAttributesEditor method clearListeners.

private void clearListeners() {
    Engine engine = framework.getEngine();
    engine.removeQualifierListener(qualifierListener);
    engine.removeElementAttributeListener(currentQualifier, elementAttributeListener);
    engine.removeElementListener(currentQualifier, elementListener);
}
Also used : Engine(com.ramussoft.common.Engine)

Example 49 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class ElementAttributesEditor method reload.

protected void reload() {
    CloseEvent event = new CloseEvent(this);
    CloseListener[] listeners = getCloseListeners();
    for (CloseListener listener : listeners) {
        listener.closed(event);
        removeCloseListener(listener);
    }
    loadCurrentQualifierAttributes();
    Engine engine = framework.getEngine();
    AccessRules rules = framework.getAccessRules();
    getters = new ValueGetter[attributes.size()];
    renderers = new TableCellRenderer[attributes.size()];
    values = new Object[attributes.size()];
    saveValues = new boolean[attributes.size()];
    Arrays.fill(saveValues, true);
    Arrays.fill(getters, new ValueGetter() {

        @Override
        public Object getValue(TableNode node, int index) {
            return node.getValueAt(index);
        }
    });
    for (int i = 0; i < attributes.size(); i++) {
        Attribute attr = attributes.get(i).attribute;
        AttributePlugin plugin = framework.findAttributePlugin(attr);
        if (plugin instanceof TabledAttributePlugin) {
            ValueGetter getter = ((TabledAttributePlugin) plugin).getValueGetter(attr, engine, framework, this);
            if (getter != null)
                getters[i] = getter;
        }
        renderers[i] = plugin.getTableCellRenderer(engine, rules, attr);
    }
    loadElement();
}
Also used : CloseEvent(com.ramussoft.gui.qualifier.table.event.CloseEvent) TabledAttributePlugin(com.ramussoft.gui.qualifier.table.TabledAttributePlugin) AttributePlugin(com.ramussoft.gui.common.AttributePlugin) Attribute(com.ramussoft.common.Attribute) TabledAttributePlugin(com.ramussoft.gui.qualifier.table.TabledAttributePlugin) ValueGetter(com.ramussoft.gui.qualifier.table.ValueGetter) CloseListener(com.ramussoft.gui.qualifier.table.event.CloseListener) TableNode(com.ramussoft.gui.qualifier.table.TableNode) AccessRules(com.ramussoft.common.AccessRules) Engine(com.ramussoft.common.Engine)

Example 50 with Engine

use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.

the class ElementAttributesEditor method loadElement.

protected void loadElement() {
    loadCurrentQualifierAttributes();
    Engine engine = framework.getEngine();
    for (int i = 0; i < attributes.size(); i++) {
        Attribute attr = attributes.get(i).attribute;
        values[i] = engine.getAttribute(currentElement, attr);
    }
    synchronized (lock) {
        table.getSelectionModel().removeListSelectionListener(listSelectionListener);
        model.fireTableDataChanged();
        table.getSelectionModel().addListSelectionListener(listSelectionListener);
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Engine(com.ramussoft.common.Engine)

Aggregations

Engine (com.ramussoft.common.Engine)85 Attribute (com.ramussoft.common.Attribute)32 ArrayList (java.util.ArrayList)30 Element (com.ramussoft.common.Element)27 Qualifier (com.ramussoft.common.Qualifier)22 AccessRules (com.ramussoft.common.AccessRules)21 List (java.util.List)19 IEngine (com.ramussoft.common.IEngine)15 Row (com.ramussoft.database.common.Row)13 IOException (java.io.IOException)11 SQLException (java.sql.SQLException)11 PluginFactory (com.ramussoft.common.PluginFactory)8 PluginProvider (com.ramussoft.common.PluginProvider)8 Journaled (com.ramussoft.common.journal.Journaled)8 CachedEngine (com.ramussoft.common.cached.CachedEngine)7 Hashtable (java.util.Hashtable)7 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)6 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)5 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)5 MemoryDatabase (com.ramussoft.database.MemoryDatabase)5