Search in sources :

Example 81 with Qualifier

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

the class Application method patchData.

/*
     * Create all needed system qualifiers and attributes.
	 */
private void patchData(Engine engine) {
    Journaled journal = (Journaled) engine;
    journal.startUserTransaction();
    Attribute textAttribute1 = createAttribute(TEXT_ATTRIBUTE1, new AttributeType("Core", "Text"), engine);
    Attribute textAttribute2 = createAttribute(TEXT_ATTRIBUTE2, new AttributeType("Core", "Text"), engine);
    Attribute doubleAttribute1 = createAttribute(DOUBLE_ATTRIBUTE1, new AttributeType("Core", "Double"), engine);
    Qualifier qualifier1 = engine.getSystemQualifier(QUALIFIER1);
    if (qualifier1 == null) {
        qualifier1 = engine.createSystemQualifier();
        qualifier1.getAttributes().add(textAttribute1);
        qualifier1.getAttributes().add(textAttribute2);
        qualifier1.getAttributes().add(doubleAttribute1);
        qualifier1.setName(QUALIFIER1);
        engine.updateQualifier(qualifier1);
    }
    journal.commitUserTransaction();
    // User will not be able to undo these changes.
    journal.setNoUndoPoint();
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) Attribute(com.ramussoft.common.Attribute) AttributeType(com.ramussoft.common.AttributeType) Qualifier(com.ramussoft.common.Qualifier)

Example 82 with Qualifier

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

the class TableChartAttributePlugin method getAttributeEditor.

@Override
public AttributeEditor getAttributeEditor(final Engine engine, final AccessRules rules, final Element element, final Attribute attribute, AttributeEditor oldAttributeEditor) {
    return new AbstractAttributeEditor() {

        @Override
        public Object setValue(Object value) {
            return null;
        }

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

        @Override
        public JComponent getComponent() {
            ChartDataFramework chartDataFramework = ChartDataFramework.getChartDataFramework(engine);
            ChartSource source = new ChartSource(engine) {

                @Override
                public List<Element> getElements() {
                    List<Element> res = new ArrayList<Element>();
                    for (QualifierSource source : qualifierSources) {
                        if (QualifierSource.ELEMENTS_LOAD_TYPE_ALL.equals(source.getElementsLoadType())) {
                            FilterSource filterSource = source.getFilterSources().get(0);
                            Qualifier qualifier = source.getQualifier();
                            if (StandardAttributesPlugin.isTableQualifier(qualifier) && filterSource.getAttribute().equals(StandardAttributesPlugin.getTableElementIdAttribute(engine))) {
                                res.addAll(StandardAttributesPlugin.getOrderedTableElements(engine, StandardAttributesPlugin.getAttributeForTable(engine, qualifier), element));
                            } else
                                res.addAll(engine.findElements(qualifier.getId(), filterSource.getAttribute(), Long.parseLong(filterSource.getValue())));
                        } else
                            for (ElementSource elementSource : source.getElementSources()) res.add(elementSource.getElement());
                    }
                    return res;
                }
            };
            TableChartPersistent tcp = (TableChartPersistent) engine.getAttribute(null, attribute);
            Element chartElement = engine.getElement(tcp.getOtherElementId());
            source.load(chartElement);
            ChartDataPlugin chartDataPlugin = chartDataFramework.getChartDataPlugin(source.getChartType());
            JFreeChart freeChart = chartDataPlugin.createChart(element, source);
            return new ChartPanel(freeChart);
        }
    };
}
Also used : FilterSource(com.ramussoft.chart.FilterSource) ChartPanel(org.jfree.chart.ChartPanel) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) ChartDataFramework(com.ramussoft.chart.ChartDataFramework) JFreeChart(org.jfree.chart.JFreeChart) QualifierSource(com.ramussoft.chart.QualifierSource) ChartDataPlugin(com.ramussoft.chart.ChartDataPlugin) AbstractAttributeEditor(com.ramussoft.gui.common.AbstractAttributeEditor) ChartSource(com.ramussoft.chart.ChartSource) TableChartPersistent(com.ramussoft.chart.core.TableChartPersistent) Qualifier(com.ramussoft.common.Qualifier) ElementSource(com.ramussoft.chart.ElementSource)

Example 83 with Qualifier

use of com.ramussoft.common.Qualifier 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());
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JLabel(javax.swing.JLabel) IOException(java.io.IOException) AbstractListModel(javax.swing.AbstractListModel) Collator(java.text.Collator) JFileChooser(javax.swing.JFileChooser) FileOutputStream(java.io.FileOutputStream) Qualifier(com.ramussoft.common.Qualifier) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) TableLayout(info.clearthought.layout.TableLayout) JList(javax.swing.JList)

Example 84 with Qualifier

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

the class IDEF0ViewPlugin method importFromIdl.

protected void importFromIdl() {
    JFileChooser fc = new JFileChooser();
    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";
        }
    });
    if (fc.showOpenDialog(framework.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
        try {
            ((Journaled) engine).startUserTransaction();
            Qualifier qualifier = engine.createQualifier();
            Attribute name = null;
            String aName = ResourceLoader.getString("name");
            for (Attribute a : engine.getAttributes()) {
                if (a.getAttributeType().toString().equals("Core.Text")) {
                    if (aName.equals(a.getName()))
                        name = a;
                }
            }
            if (name == null) {
                name = engine.createAttribute(new AttributeType("Core", "Text", true));
                name.setName(aName);
                engine.updateAttribute(name);
            }
            qualifier.getAttributes().add(name);
            qualifier.setAttributeForName(name.getId());
            IDEF0Plugin.installFunctionAttributes(qualifier, engine);
            DataPlugin plugin = NDataPluginFactory.getDataPlugin(qualifier, engine, rules);
            File file = fc.getSelectedFile();
            plugin.importFromIDL(plugin, "cp1251", new FileInputStream(file));
            ((Journaled) engine).commitUserTransaction();
            OpenDiagram openDiagram = new OpenDiagram(qualifier, -1l);
            framework.propertyChanged(OPEN_DIAGRAM, openDiagram);
        } catch (Exception e) {
            ((Journaled) engine).rollbackUserTransaction();
            e.printStackTrace();
            JOptionPane.showMessageDialog(framework.getMainFrame(), "Формат выбранного вами файла IDL не поддерживается.");
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) FileInputStream(java.io.FileInputStream) ParseException(java.text.ParseException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) Journaled(com.ramussoft.common.journal.Journaled) JFileChooser(javax.swing.JFileChooser) AttributeType(com.ramussoft.common.AttributeType) Qualifier(com.ramussoft.common.Qualifier) FileFilter(javax.swing.filechooser.FileFilter) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) File(java.io.File)

Example 85 with Qualifier

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

the class ModelsView method createModelsPanel.

protected void createModelsPanel() {
    if (this.modelsPanel != null)
        this.modelsPanel.close();
    Qualifier modelTree = IDEF0Plugin.getModelTree(engine);
    modelTree = engine.getQualifier(modelTree.getId());
    if (modelTree == null) {
        final com.ramussoft.idef0.idef0.oldmodelsview.ModelsPanel modelsPanel = new com.ramussoft.idef0.idef0.oldmodelsview.ModelsPanel(engine, framework) {

            @Override
            public boolean isDisabeUpdate() {
                return disableUpdated;
            }
        };
        modelsPanel.getTree().getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

            @Override
            public void valueChanged(TreeSelectionEvent e) {
                openDiagram.setEnabled(modelsPanel.getTree().getSelectionPath() != null);
            }
        });
        modelsPanel.getTree().setComponentPopupMenu(createPopupMenu());
        modelsPanel.getTree().addTreeSelectionListener(new TreeSelectionListener() {

            @Override
            public void valueChanged(TreeSelectionEvent e) {
                ch1();
                modelNode = getActiveNode1();
                while ((modelNode != null) && (!(modelNode instanceof ModelsNode)) && (modelNode instanceof Row)) modelNode = ((Row) modelNode).getParent();
                modelProperties.setEnabled((modelNode instanceof ModelsNode) && (rules.canUpdateQualifier(((ModelsNode) modelNode).getQualifier().getId())));
            }
        });
        modelsPanel.getTreeModel().addTreeModelListener(new TreeModelListener() {

            @Override
            public void treeNodesChanged(TreeModelEvent e) {
                ch1();
            }

            @Override
            public void treeNodesInserted(TreeModelEvent e) {
                ch1();
            }

            @Override
            public void treeNodesRemoved(TreeModelEvent e) {
                ch1();
            }

            @Override
            public void treeStructureChanged(TreeModelEvent e) {
                ch1();
            }
        });
        contentPanel.add(modelsPanel, BorderLayout.CENTER);
        modelsPanel.getTree().setComponentPopupMenu(createPopupMenu());
        this.modelsPanel = modelsPanel;
    } else {
        final ModelsPanel modelsPanel = new ModelsPanel(engine, framework) {

            @Override
            public boolean isDisabeUpdate() {
                return disableUpdated;
            }
        };
        modelsPanel.getTree().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                openDiagram.setEnabled(modelsPanel.canOpen());
            }
        });
        modelsPanel.getTree().setComponentPopupMenu(createPopupMenu());
        modelsPanel.getTree().getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                ch();
                modelNode = getActiveNode();
                while ((modelNode != null) && (!(modelNode instanceof ModelsNode)) && (modelNode instanceof RowNode)) modelNode = ((RowNode) modelNode).getParent();
                modelProperties.setEnabled((modelNode instanceof ModelsNode) && (rules.canUpdateQualifier(((ModelsNode) modelNode).getQualifier().getId())));
            }
        });
        contentPanel.add(modelsPanel, BorderLayout.CENTER);
        modelsPanel.getTree().getTable().setComponentPopupMenu(createPopupMenu());
        this.modelsPanel = modelsPanel;
    }
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) RowNode(com.ramussoft.gui.qualifier.table.RowNode) TreeModelListener(javax.swing.event.TreeModelListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) ListSelectionListener(javax.swing.event.ListSelectionListener) Qualifier(com.ramussoft.common.Qualifier) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Row(com.ramussoft.database.common.Row)

Aggregations

Qualifier (com.ramussoft.common.Qualifier)157 Attribute (com.ramussoft.common.Attribute)72 Element (com.ramussoft.common.Element)59 ArrayList (java.util.ArrayList)45 Engine (com.ramussoft.common.Engine)22 Row (com.ramussoft.database.common.Row)17 Row (com.ramussoft.pb.Row)14 List (java.util.List)12 Hashtable (java.util.Hashtable)11 QualifierEvent (com.ramussoft.common.event.QualifierEvent)10 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 AttributeType (com.ramussoft.common.AttributeType)8 RowSet (com.ramussoft.database.common.RowSet)8 DataPlugin (com.ramussoft.pb.DataPlugin)8 NFunction (com.ramussoft.pb.data.negine.NFunction)8 AttributeEvent (com.ramussoft.common.event.AttributeEvent)7 Journaled (com.ramussoft.common.journal.Journaled)7 RowMapper (com.ramussoft.jdbc.RowMapper)7 IEngine (com.ramussoft.common.IEngine)6