Search in sources :

Example 16 with AccessRules

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;
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Attribute(com.ramussoft.common.Attribute) RowTreeTableComponent(com.ramussoft.gui.qualifier.table.RowTreeTableComponent) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) SelectionEvent(com.ramussoft.gui.qualifier.table.event.SelectionEvent) AccessRules(com.ramussoft.common.AccessRules) RowRootCreater(com.ramussoft.gui.qualifier.table.RowRootCreater) Row(com.ramussoft.database.common.Row) AbstractAction(javax.swing.AbstractAction) Engine(com.ramussoft.common.Engine) SelectionListener(com.ramussoft.gui.qualifier.table.event.SelectionListener)

Example 17 with AccessRules

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);
            }
        }
    };
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) Attribute(com.ramussoft.common.Attribute) JLabel(javax.swing.JLabel) AttributePreferenciesEditor(com.ramussoft.gui.common.AttributePreferenciesEditor) OtherElementPropertyPersistent(com.ramussoft.core.attribute.simple.OtherElementPropertyPersistent) AccessRules(com.ramussoft.common.AccessRules) Qualifier(com.ramussoft.common.Qualifier) ItemListener(java.awt.event.ItemListener) TableLayout(info.clearthought.layout.TableLayout) Engine(com.ramussoft.common.Engine)

Example 18 with AccessRules

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;
}
Also used : JPanel(javax.swing.JPanel) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) ElementListPersistent(com.ramussoft.core.attribute.simple.ElementListPersistent) AdjustmentEvent(java.awt.event.AdjustmentEvent) ElementListPropertyPersistent(com.ramussoft.core.attribute.simple.ElementListPropertyPersistent) JComponent(javax.swing.JComponent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) SelectType(com.ramussoft.gui.qualifier.table.SelectType) Properties(java.util.Properties) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) SelectionEvent(com.ramussoft.gui.qualifier.table.event.SelectionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) AdjustmentListener(java.awt.event.AdjustmentListener) AccessRules(com.ramussoft.common.AccessRules) JSplitPane(javax.swing.JSplitPane) Engine(com.ramussoft.common.Engine)

Example 19 with AccessRules

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);
    }
}
Also used : PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) UniversalPersistentFactory(com.ramussoft.core.persistent.UniversalPersistentFactory) EngineLogExtension(com.ramussoft.common.logger.EngineLogExtension) Log(com.ramussoft.common.logger.Log) ILog(com.ramussoft.common.logger.ILog) PersistentsPluginProvider(com.ramussoft.core.persistent.PersistentsPluginProvider) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) Properties(java.util.Properties) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) UpdateEventCallback(com.ramussoft.common.logger.UpdateEventCallback) Journaled(com.ramussoft.common.journal.Journaled) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) AccessRules(com.ramussoft.common.AccessRules) Event(com.ramussoft.common.logger.Event) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Plugin(com.ramussoft.common.Plugin) PersistentsPlugin(com.ramussoft.core.persistent.PersistentsPlugin) AbstractPlugin(com.ramussoft.common.AbstractPlugin)

Example 20 with AccessRules

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;
        }
    };
}
Also used : Bounds(com.ramussoft.reportgef.model.Bounds) Label(com.ramussoft.report.editor.xml.components.Label) AccessRules(com.ramussoft.common.AccessRules) AbstractComponentFactory(com.ramussoft.reportgef.AbstractComponentFactory) Engine(com.ramussoft.common.Engine) Diagram(com.ramussoft.reportgef.gui.Diagram)

Aggregations

AccessRules (com.ramussoft.common.AccessRules)23 Engine (com.ramussoft.common.Engine)21 Attribute (com.ramussoft.common.Attribute)9 PluginFactory (com.ramussoft.common.PluginFactory)5 Row (com.ramussoft.database.common.Row)5 ArrayList (java.util.ArrayList)5 PluginProvider (com.ramussoft.common.PluginProvider)4 Qualifier (com.ramussoft.common.Qualifier)4 MemoryDatabase (com.ramussoft.database.MemoryDatabase)4 RowRootCreater (com.ramussoft.gui.qualifier.table.RowRootCreater)4 RowTreeTableComponent (com.ramussoft.gui.qualifier.table.RowTreeTableComponent)4 ActionEvent (java.awt.event.ActionEvent)4 AbstractAction (javax.swing.AbstractAction)4 AttributePreferenciesEditor (com.ramussoft.gui.common.AttributePreferenciesEditor)3 TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)3 SelectionEvent (com.ramussoft.gui.qualifier.table.event.SelectionEvent)3 AbstractComponentFactory (com.ramussoft.reportgef.AbstractComponentFactory)3 Diagram (com.ramussoft.reportgef.gui.Diagram)3 Bounds (com.ramussoft.reportgef.model.Bounds)3 File (java.io.File)3