Search in sources :

Example 11 with DataPlugin

use of com.ramussoft.pb.DataPlugin 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 12 with DataPlugin

use of com.ramussoft.pb.DataPlugin in project ramus by Vitaliy-Yakovchuk.

the class NDataPluginFactory method getTemplateDataPlugin.

public static DataPlugin getTemplateDataPlugin() {
    DataPlugin res = null;
    synchronized (lock) {
        if (templateDataPlugin != null) {
            res = templateDataPlugin;
            templateDataPlugin = null;
        } else {
            res = createTemplateDataPlugin();
        }
    }
    initTemplate();
    return res;
}
Also used : DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin)

Example 13 with DataPlugin

use of com.ramussoft.pb.DataPlugin in project ramus by Vitaliy-Yakovchuk.

the class NDataPluginFactory method getDataPlugin.

public static DataPlugin getDataPlugin(Qualifier baseFunction, Engine e, AccessRules accessRules) {
    NDataPlugin dataPlugin = getExistingDataPlugin(e);
    if (dataPlugin == null) {
        dataPlugin = new NDataPlugin(e, accessRules);
        e.setPluginProperty("IDEF0", "DataPlugin", dataPlugin);
    }
    if (baseFunction == null)
        return dataPlugin;
    DataPlugin dp = (DataPlugin) e.getPluginProperty("IDEF0", "BaseFunction_" + baseFunction.getId());
    if (dp == null) {
        NDataPluginFactory dataPluginFactory = new NDataPluginFactory(e, baseFunction, dataPlugin);
        List<NDataPluginFactory> list = (List<NDataPluginFactory>) e.getPluginProperty("IDEF0", "NDataPluginFactoryList");
        if (list == null) {
            list = new ArrayList<NDataPluginFactory>();
            e.setPluginProperty("IDEF0", "NDataPluginFactoryList", list);
            e.setPluginProperty("IDEF0", "NDataPluginRefreshId", new Long(-1l));
        }
        list.add(dataPluginFactory);
        dp = dataPluginFactory.createDataPlugin();
        e.setPluginProperty("IDEF0", "BaseFunction_" + baseFunction.getId(), dp);
    }
    initTemplate();
    return dp;
}
Also used : NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) ArrayList(java.util.ArrayList) List(java.util.List) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin)

Example 14 with DataPlugin

use of com.ramussoft.pb.DataPlugin 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 15 with DataPlugin

use of com.ramussoft.pb.DataPlugin in project ramus by Vitaliy-Yakovchuk.

the class AbstractDataPlugin method loadFromParalel.

public void loadFromParalel(final File file, final GUIFramework framework) throws IOException {
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, false);
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, true);
                framework.showAnimation(ResourceLoader.getString("Wait.Message"));
                MemoryDatabase md = new MemoryDatabase() {

                    protected String getJournalDirectoryName(String tmp) {
                        return null;
                    }

                    @Override
                    protected File getFile() {
                        return file;
                    }
                };
                LoadFromParalelDialog dialog = new LoadFromParalelDialog(framework.getMainFrame(), md.getEngine("idef0"));
                if (dialog.showModal()) {
                    ((Journaled) getEngine()).startUserTransaction();
                    try {
                        DataPlugin fdp = NDataPluginFactory.getDataPlugin(null, md.getEngine("idef0"), md.getAccessRules("idef0"));
                        ModelParaleler paraleler = new ModelParaleler(fdp, AbstractDataPlugin.this, framework);
                        paraleler.loadFromParalel(dialog.isImportAll(), dialog.getSelected());
                    } finally {
                        ((Journaled) getEngine()).commitUserTransaction();
                    }
                }
                FileIEngineImpl impl = (FileIEngineImpl) md.getEngine("idef0").getDeligate();
                impl.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                framework.propertyChanged(ModelsView.SET_UPDATE_ALL_MODELS, true);
                framework.propertyChanged(ModelsView.REFRESH_ALL_MODELS);
                framework.propertyChanged(IDEF0TabView.DISABLE_SILENT_REFRESH, false);
                framework.hideAnimation();
            }
        }
    };
    t.start();
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) FileIEngineImpl(com.ramussoft.core.impl.FileIEngineImpl) ModelParaleler(com.ramussoft.idef0.ModelParaleler) LoadFromParalelDialog(com.ramussoft.pb.idef.frames.LoadFromParalelDialog) MemoryDatabase(com.ramussoft.database.MemoryDatabase) DataPlugin(com.ramussoft.pb.DataPlugin) NDataPlugin(com.ramussoft.pb.data.negine.NDataPlugin) IOException(java.io.IOException)

Aggregations

DataPlugin (com.ramussoft.pb.DataPlugin)17 NDataPlugin (com.ramussoft.pb.data.negine.NDataPlugin)9 Qualifier (com.ramussoft.common.Qualifier)8 Row (com.ramussoft.pb.Row)7 Journaled (com.ramussoft.common.journal.Journaled)5 IOException (java.io.IOException)5 Attribute (com.ramussoft.common.Attribute)4 NFunction (com.ramussoft.pb.data.negine.NFunction)4 ProjectOptions (com.dsoft.pb.idef.elements.ProjectOptions)3 Element (com.ramussoft.common.Element)3 Engine (com.ramussoft.common.Engine)3 Function (com.ramussoft.pb.Function)3 FRectangle (com.dsoft.pb.types.FRectangle)2 AttributeType (com.ramussoft.common.AttributeType)2 FileIEngineImpl (com.ramussoft.core.impl.FileIEngineImpl)2 MemoryDatabase (com.ramussoft.database.MemoryDatabase)2 Row (com.ramussoft.database.common.Row)2 AbstractAttributeEditor (com.ramussoft.gui.common.AbstractAttributeEditor)2 ModelParaleler (com.ramussoft.idef0.ModelParaleler)2 NRow (com.ramussoft.pb.data.negine.NRow)2