Package com.nexirius.framework.datamodel.persistence

Source Code of com.nexirius.framework.datamodel.persistence.TestPersistence$TestModel

//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
/*
* Created by IntelliJ IDEA.
* User: F503219
* Date: 26.03.2004
* Time: 14:01:02
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
package com.nexirius.framework.datamodel.persistence;

import com.nexirius.framework.datamodel.DataModel;
import com.nexirius.framework.datamodel.StringModel;
import com.nexirius.framework.datamodel.StructModel;

public class TestPersistence {



    public static final String FIELDNAME = "PersistenceChooserModel";

    static class TestPersistenceOpenAdapter implements PersistenceOpenAdapter {
        public void openPersistentModel(PersistenceManager manager, String environmentName, String identifier) {
            System.out.println(identifier);

            try {
                DataModel model = manager.load(environmentName, identifier);
                System.out.println(model.dragData());
                manager.close(environmentName, model, true);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    static class TestModel extends StructModel {
        public static String FIELDNAME_IDENTIFIER = "PersistenceIdentifier";
        public static String FIELDNAME_TYPE = "PersistenceType";

        StringModel identifier;
        StringModel type;

        public TestModel() {
            super(FIELDNAME);
            init();
        }

        public TestModel(String type) {
            super(FIELDNAME);
            init();
            setType(type);
        }

        public void setIdentifier(String identifier) {
            this.identifier.setText(identifier);
        }

        public String getIdentifier() {
            return this.identifier.getText();
        }

        public void setType(String type) {
            this.type.setText(type);
        }

        public String getType() {
            return this.type.getText();
        }


        private void init() {
            append(identifier = new StringModel("", FIELDNAME_IDENTIFIER));
            append(type = new StringModel("", FIELDNAME_TYPE));
        }
    }

    public static void main(String argv[]) {
        String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

        try {
            javax.swing.UIManager.setLookAndFeel(plaf);
        } catch (Exception e) {
            System.out.println("Can't set '" + plaf + "' look and feel");

            System.exit(0);
        }

        try {
            if (argv.length == 0) {
                throw new Exception("Usage: parameter0 = rootDirectory parameter++ = environments");
            }

            com.nexirius.util.resource.ClientResourceImpl resources = new com.nexirius.util.resource.ClientResourceImpl("PersistenceTest");
            com.nexirius.framework.dataviewer.ViewerFactory factory = new com.nexirius.framework.dataviewer.ViewerFactory(resources);

            factory.setCommandProcessor(new com.nexirius.framework.command.DefaultProcessor());
            FileSystemPersistence.init(argv[0]);
            System.out.println("FileSystemPersistence.init(" + argv[0] + ")");
            PersistenceManager manager = FileSystemPersistence.instance();

            for (int n = 1; n < argv.length; ++n) {
                manager.addEnvironment(new DirectoryEnvironment(argv[n], argv[n], true));

                if (n == 2) {
                    ((DirectoryEnvironment) manager.getEnvironment(argv[n])).setExtension(".ext");
                    ((DirectoryEnvironment) manager.getEnvironment(argv[n])).setUseMagicNumber(true);
                }

                for (int i = 0; i <= 20 / n; ++i) {
                    TestModel pm = new TestModel("model " + i);
                    pm.setIdentifier("identifier_" + n + "_" + i);
                    pm.setInstanceName("identifier_" + n + "_" + i);
                    try {
                        manager.store(pm, argv[n]);
                    } catch (Exception ex) {
                        System.out.println(ex.getMessage());
                    }
                }
            }

            PersistenceChooserModel model = new PersistenceChooserModel(manager, new TestPersistenceOpenAdapter(), new TestModel(), null);
            model.setEnvironment("env1");
            javax.swing.JFrame frame = new javax.swing.JFrame();

            frame.getContentPane().setLayout(new java.awt.BorderLayout());

            com.nexirius.framework.dataviewer.DataViewer viewer = factory.createDefaultEditor(model);

            viewer.setLayout(new PersistenceChooserModel.LayoutWithEnvironment());

            frame.getContentPane().add(java.awt.BorderLayout.CENTER, viewer.getJComponent());
            frame.pack();

            frame.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
TOP

Related Classes of com.nexirius.framework.datamodel.persistence.TestPersistence$TestModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.