Package fr.soleil.lib.flyscan.model.parsing.configuration

Examples of fr.soleil.lib.flyscan.model.parsing.configuration.Configuration


            while ((sCurrentLine = br.readLine()) != null) {
                sb.append(sCurrentLine);
            }
            String content = sb.toString();
            String[] lines = content.split(System.getProperty("line.separator"));
            Configuration result = ConfigParser.getInstance().parse("ffs_cfg_example_2.cfg", lines);
            System.out.println(result);

//            List<Plugin> results = PluginParser.newInstance().parse("pySensor.prop");
//            for (Plugin result : results) {
//                System.out.println(result);
View Full Code Here


                    configName = configName.replace("*", "").trim();
                    if (!configName.isEmpty()) {
                        try {
                            // Write config
                            TangoAttribute attribute = new TangoAttribute(getModel() + "/configuration");
                            Configuration config = tabbedPane.getConfiguration(index);
                            String unparsedConfig = ConfigParser.getInstance().deParse(config, getPlugins());
                            attribute.write(unparsedConfig);
                            // Start scan
                            TangoCommand startCommand = new TangoCommand(getModel(), "Start");
                            startCommand.execute();
                        } catch (DevFailed e) {
                            String message = DevFailedUtils.toString(e);
                            LOGGER.log(Level.SEVERE, message);
//                            System.err.println(message);
                        }
                    }
                }

            }
        });

        GridBagConstraints startButtonGridBagConstraints = new GridBagConstraints();
        startButtonGridBagConstraints.gridx = 0;
        startButtonGridBagConstraints.gridy = 0;
        startButtonGridBagConstraints.weightx = 0.25;
        startButtonGridBagConstraints.weighty = 0;
        startButtonGridBagConstraints.ipadx = 0;
        startButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        startButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
        startButtonGridBagConstraints.insets = new Insets(5, 5, 5, 0);
        buttonPanel.add(startButton, startButtonGridBagConstraints);

        stopButton = new StringButton();
        stopButton.setIcon(Utilities.ICONS.getIcon("flyscan.stop"));
        stopButton.setButtonLook(true);

        GridBagConstraints stopButtonGridBagConstraints = new GridBagConstraints();
        stopButtonGridBagConstraints.gridx = 1;
        stopButtonGridBagConstraints.gridy = 0;
        stopButtonGridBagConstraints.weightx = 0.25;
        stopButtonGridBagConstraints.weighty = 0;
        stopButtonGridBagConstraints.ipadx = 0;
        stopButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        stopButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
        stopButtonGridBagConstraints.insets = new Insets(5, 5, 5, 0);
        buttonPanel.add(stopButton, stopButtonGridBagConstraints);

        pauseButton = new StringButton();
        pauseButton.setIcon(Utilities.ICONS.getIcon("flyscan.pause"));
        pauseButton.setButtonLook(true);

        GridBagConstraints pauseButtonGridBagConstraints = new GridBagConstraints();
        pauseButtonGridBagConstraints.gridx = 2;
        pauseButtonGridBagConstraints.gridy = 0;
        pauseButtonGridBagConstraints.weightx = 0.25;
        pauseButtonGridBagConstraints.weighty = 0;
        pauseButtonGridBagConstraints.ipadx = 0;
        pauseButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        pauseButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
        pauseButtonGridBagConstraints.insets = new Insets(5, 5, 5, 0);
        buttonPanel.add(pauseButton, pauseButtonGridBagConstraints);

        restartButton = new StringButton();
        restartButton.setIcon(Utilities.ICONS.getIcon("flyscan.resume"));
        restartButton.setButtonLook(true);

        GridBagConstraints restartButtonGridBagConstraints = new GridBagConstraints();
        restartButtonGridBagConstraints.gridx = 3;
        restartButtonGridBagConstraints.gridy = 0;
        restartButtonGridBagConstraints.weightx = 0.25;
        restartButtonGridBagConstraints.weighty = 0;
        restartButtonGridBagConstraints.ipadx = 0;
        restartButtonGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        restartButtonGridBagConstraints.anchor = GridBagConstraints.EAST;
        restartButtonGridBagConstraints.insets = new Insets(5, 5, 5, 5);
        buttonPanel.add(restartButton, restartButtonGridBagConstraints);

        GridBagConstraints buttonPanelGridBagConstraints = new GridBagConstraints();
        buttonPanelGridBagConstraints.gridx = 2;
        buttonPanelGridBagConstraints.gridy = 0;
        buttonPanelGridBagConstraints.weightx = 0.1;
        buttonPanelGridBagConstraints.weighty = 0;
        buttonPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
        buttonPanelGridBagConstraints.fill = GridBagConstraints.NONE;
        buttonPanelGridBagConstraints.anchor = GridBagConstraints.WEST;
        scanInfoAndCommandsPanel.add(buttonPanel, buttonPanelGridBagConstraints);

        scanProgressPanel = new JPanel(new GridBagLayout());

        GridBagConstraints gc1 = new GridBagConstraints();
        gc1.gridx = 0;
        gc1.gridy = 0;
        gc1.weightx = 0.05;
        gc1.weighty = 0;
        gc1.fill = GridBagConstraints.NONE;
        gc1.anchor = GridBagConstraints.WEST;
        scanProgressPanel.add(new JLabel("Scan Progress: "), gc1);

        GridBagConstraints gc2 = new GridBagConstraints();
        gc2.gridx = 1;
        gc2.gridy = 0;
        gc2.weightx = 0.95;
        gc2.weighty = 0;
        gc2.fill = GridBagConstraints.HORIZONTAL;
        gc2.anchor = GridBagConstraints.WEST;
        scanProgressPanel.add(scanProgressBar, gc2);

        GridBagConstraints progressPanelGridBagConstraints = new GridBagConstraints();
        progressPanelGridBagConstraints.gridx = 3;
        progressPanelGridBagConstraints.gridy = 0;
        progressPanelGridBagConstraints.weightx = 0.8;
        progressPanelGridBagConstraints.weighty = 0;
        progressPanelGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        progressPanelGridBagConstraints.anchor = GridBagConstraints.WEST;
        progressPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
        scanInfoAndCommandsPanel.add(scanProgressPanel, progressPanelGridBagConstraints);

        JPanel currentConfigNamePanel = new JPanel(new BorderLayout());
        currentConfigNamePanel.add(new JLabel("Current config name: "), BorderLayout.WEST);
        currentConfigNamePanel.add(currentConfigNameLabel, BorderLayout.CENTER);

        scanPositionPanel = new JPanel(new BorderLayout());
        scanPositionPanel.add(new JLabel("Scan Position: "), BorderLayout.WEST);
        scanPositionPanel.add(scanPositionLabel, BorderLayout.CENTER);

        GridBagConstraints currentConfigNamePanelGridBagConstraints = new GridBagConstraints();
        currentConfigNamePanelGridBagConstraints.gridx = 0;
        currentConfigNamePanelGridBagConstraints.gridy = 0;
        currentConfigNamePanelGridBagConstraints.weightx = 0.1;
        currentConfigNamePanelGridBagConstraints.weighty = 0;
        currentConfigNamePanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
        currentConfigNamePanelGridBagConstraints.fill = GridBagConstraints.NONE;
        currentConfigNamePanelGridBagConstraints.anchor = GridBagConstraints.WEST;
        scanInfoAndCommandsPanel.add(currentConfigNamePanel, currentConfigNamePanelGridBagConstraints);

        GridBagConstraints positionPanelGridBagConstraints = new GridBagConstraints();
        positionPanelGridBagConstraints.gridx = 1;
        positionPanelGridBagConstraints.gridy = 0;
        positionPanelGridBagConstraints.weightx = 0.1;
        positionPanelGridBagConstraints.weighty = 0;
        positionPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
        positionPanelGridBagConstraints.fill = GridBagConstraints.NONE;
        positionPanelGridBagConstraints.anchor = GridBagConstraints.WEST;
        scanInfoAndCommandsPanel.add(scanPositionPanel, positionPanelGridBagConstraints);

        monitoredDevicesPanel = new JPanel(new BorderLayout());
        monitoredDevicesPanel.add(monitoredDevices, BorderLayout.CENTER);

        GridBagConstraints monitoredPanelGridBagConstraints = new GridBagConstraints();
        monitoredPanelGridBagConstraints.gridx = 0;
        monitoredPanelGridBagConstraints.gridy = 1;
        monitoredPanelGridBagConstraints.weightx = 1;
        monitoredPanelGridBagConstraints.weighty = 0;
        monitoredPanelGridBagConstraints.gridwidth = 4;
        monitoredPanelGridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
        monitoredPanelGridBagConstraints.anchor = GridBagConstraints.CENTER;
        monitoredPanelGridBagConstraints.insets = new Insets(5, 5, 5, 5);
        scanInfoAndCommandsPanel.add(monitoredDevicesPanel, monitoredPanelGridBagConstraints);

        final GridBagConstraints scanInfoAndCommandsPanelConstraints = new GridBagConstraints();
        scanInfoAndCommandsPanelConstraints.gridx = 0;
        scanInfoAndCommandsPanelConstraints.gridy = 2;
        scanInfoAndCommandsPanelConstraints.weightx = 1;
        scanInfoAndCommandsPanelConstraints.weighty = 0;
        scanInfoAndCommandsPanelConstraints.fill = GridBagConstraints.HORIZONTAL;
        scanInfoAndCommandsPanelConstraints.anchor = GridBagConstraints.CENTER;

        configDevicePanel.add(scanInfoAndCommandsPanel, scanInfoAndCommandsPanelConstraints);

        this.add(configDevicePanel, devicePanelConstraints);

        tabbedPane = new CloseSaveButtonTabbedPane(expert);

        tabbedPane.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                if (e.getSource() instanceof JTabbedPane) {
                    JTabbedPane pane = (JTabbedPane) e.getSource();
                    final int selectedIndex = pane.getSelectedIndex();
                    boolean atLeastOneTabisDisplayed = (selectedIndex > -1);

                    boolean currentConfigPaneisSelected = false;

                    // If current config tab is selected, disable start button
                    if (selectedIndex > -1) {
                        String title = tabbedPane.getTitleAt(selectedIndex);
                        if ((title != null) && (title.equalsIgnoreCase(CURRENT_CONFIG))) {
                            currentConfigPaneisSelected = true;
                        }
                    }

                    startButton.setEnabled(atLeastOneTabisDisplayed && !(currentConfigPaneisSelected));
                }
            }
        });

        ActionListener menuItemActionListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JMenuItem flyScanMenuItem = (JMenuItem) e.getSource();

                loadAndDisplayConfig(isExpert, flyScanMenuItem.getText());

                JPopupMenu popupMenu = (JPopupMenu) ((FlyScanPanelMenuElement) flyScanMenuItem.getParent()).getParent();
                popupMenu.setVisible(false);

            }
        };

        ActionListener currentConfigMenuItemActionListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                JMenuItem flyScanMenuItem = (JMenuItem) e.getSource();

                loadAndDisplayCurrentConfig(isExpert, false);

                JPopupMenu popupMenu = (JPopupMenu) flyScanMenuItem.getParent();
                popupMenu.setVisible(false);

                startButton.setEnabled(false);

            }
        };

        KeyListener searchFieldKeyListener = new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    FlyScanMenu flyScanMenu = searchFlyScanMenu(e.getComponent());
                    if (flyScanMenu != null) {
                        for (JMenuItem item : flyScanMenu.getItems()) {

                            if (item.isArmed()) {
                                loadAndDisplayConfig(isExpert, item.getText().trim());
                            }

                        }
                        // Close menu
                        flyScanMenu.getPopupMenu().setVisible(false);
                    }
                }
            }
        };

        configurationMenu = new FlyScanMenu(menuItemActionListener, searchFieldKeyListener,
                currentConfigMenuItemActionListener, new FlyScanFilter());
        configurationMenu.setText("Configurations");

        if (useMock) {
            // Mock to load a config file without using the device
            mockMenu = new JMenu("Mock");

            // Create a file chooser
            final JFileChooser fcConfig = new JFileChooser();

            JMenuItem mockConfigMenuItem = new JMenuItem("Load config file");
            mockConfigMenuItem.setToolTipText("First load a plugin file");
            mockConfigMenuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    // Handle open button action.
                    int returnVal = fcConfig.showOpenDialog(FlyScanTangoBox.this);

                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fcConfig.getSelectedFile();
                        loadAndDisplayMockConfig(isExpert, file);
                    }
                }
            });
            mockMenu.add(mockConfigMenuItem);

            // Create a file chooser
            final JFileChooser fcPlugin = new JFileChooser();

            JMenuItem mockPluginMenuItem = new JMenuItem("Load plugin file");
            mockPluginMenuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    // Handle open button action.
                    int returnVal = fcPlugin.showOpenDialog(FlyScanTangoBox.this);

                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fcPlugin.getSelectedFile();
                        mockPlugins = getMockPlugins(file);
                    }
                }
            });
            mockMenu.add(mockPluginMenuItem);

        }

        pluginTarget = new FlyScanTarget();
        currentConfigTarget = new FlyScanTarget() {
            @Override
            public void setFlatStringMatrix(String[] value, int width, int height) {
                super.setFlatStringMatrix(value, width, height);

                // When current config change, reload current config tab if it is open
                refreshCurrentConfigTab();

                Configuration configuration = getCurrentConfiguration();
                if (configuration != null) {
                    String configurationName = getConfigurationName(configuration);
                    currentConfigNameLabel.setText(configurationName);
                }

            }

            protected void refreshCurrentConfigTab() {
                int index = getConfigurationTabIndex(CURRENT_CONFIG);

                if (index > -1) {
                    loadAndDisplayCurrentConfig(isExpert, true);
                }
            }

            @Override
            public void setStringMatrix(String[][] value) {
                super.setStringMatrix(value);

                // When current config change, reload current config tab if it is open
                refreshCurrentConfigTab();

                Configuration configuration = getCurrentConfiguration();
                if (configuration != null) {
                    String configurationName = getConfigurationName(configuration);
                    currentConfigNameLabel.setText(configurationName);
                }
            }
View Full Code Here

                for (int index = 0; index < cnt; index++) {
                    Component component = tabbedPane.getTabComponentAt(index);
                    final CloseSaveButtonTab closeSaveButtonTab = (CloseSaveButtonTab) component;
                    final StringButton checkButton = closeSaveButtonTab.getCheckButton();
                    final ConfigurationGUI configurationGUI = closeSaveButtonTab.getConfigurationGUI();
                    final Configuration config = configurationGUI.getConfiguration();

                    // Instead of using a comete box for connecting the check button to the 'CheckConfig' command, a
                    // TangoCommand is created to avoid displaying the check result in a popup and display it within the
                    // config error area
                    checkButton.addButtonListener(new IButtonListener() {

                        @Override
                        public void actionPerformed(EventObject event) {
                            try {
                                configurationGUI.removeCheckConfigLabelError();
                                String deParsedConfig = ConfigParser.getInstance().deParse(config, getPlugins());
                                String[] configContent = deParsedConfig.split(System.getProperty("line.separator"));
                                String[] checkResult = checkConfig(configContent);
                                if (checkResult == null) {
                                    JOptionPane.showMessageDialog(checkButton, "Configuration ok");
                                } else {
                                    StringBuffer sb = new StringBuffer();
                                    for (String s : checkResult) {
                                        sb.append(s);
                                        sb.append(System.getProperty("line.separator"));
                                    }

                                    displayCheckConfigError(configurationGUI, sb.toString());
                                }

                            } catch (DevFailed e) {
                                String message = DevFailedUtils.toString(e);
//                                System.err.println(message);
                                displayCheckConfigError(configurationGUI, message);
                                LOGGER.log(Level.SEVERE, message);
                            }

                        }
                    });

                    final JButton saveButton = closeSaveButtonTab.getSaveButton();

                    saveButton.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent e) {
                            if (closeSaveButtonTab.getTitle().trim().endsWith(Utilities.ASTERISK)) {
                                closeSaveButtonTab.setTitle(closeSaveButtonTab.getTitle().replaceAll("\\*", "").trim());
                                Configuration configuration = closeSaveButtonTab.getConfigurationGUI()
                                        .getConfiguration();
                                String deParsedConfig = ConfigParser.getInstance().deParse(configuration, getPlugins());
                                // System.out.println(deParsedConfig);
                                String[] arguments = deParsedConfig.split(System.getProperty("line.separator"));

View Full Code Here

        return typeAndDimension;
    }

    protected Configuration getCurrentConfiguration() {
        Configuration configuration = null;
        if (currentConfigTarget != null) {
            String[] currentConfig = currentConfigTarget.getFlatStringMatrix();

            try {
                if (currentConfig != null && currentConfig.length > 0) {
View Full Code Here

        content[46] = "enable = true";
        content[47] = "action = preScan";
        content[48] = "parameter:value:execution_time_ms = 2000";

        ConfigParser configParser = ConfigParser.getInstance();
        Configuration configuration = configParser.parse("configTest", content);

        assertNotNull(configuration);

        assertEquals(4, configuration.getSections().size());

        InfoSection infoSection = null;
        for (Section s : configuration.getSections()) {
            if (s instanceof InfoSection) {
                infoSection = (InfoSection) s;
            }
        }

        assertNotNull(infoSection);

        assertEquals(0, infoSection.getObjects().size());

        assertEquals(7, infoSection.getEntries().size());

        ActorSection actorSection = null;
        for (Section s : configuration.getSections()) {
            if (s instanceof ActorSection) {
                actorSection = (ActorSection) s;
            }
        }
View Full Code Here

                protected Map<Configuration, List<Plugin>> doInBackground() throws Exception {
                    String[] configContent = readCurrentConfig();

                    // Parse config
                    ConfigParser parser = ConfigParser.getInstance();
                    Configuration configuration = parser.parse(CURRENT_CONFIG, configContent);

                    // Parse plugins
                    List<Plugin> plugins = getPlugins();
                    Map<Configuration, List<Plugin>> map = new HashMap<Configuration, List<Plugin>>();
                    map.put(configuration, plugins);
                    return map;
                }

                @Override
                protected void done() {
                    // Display configuration for edition
                    try {
                        Map<Configuration, List<Plugin>> map = get();
                        if (map != null && !map.isEmpty()) {
                            List<Plugin> tmpPlugins = null;
                            Configuration tmpConfiguration = null;
                            for (Entry<Configuration, List<Plugin>> en : map.entrySet()) {
                                tmpConfiguration = en.getKey();
                                tmpPlugins = en.getValue();
                            }
                            if (tmpConfiguration != null && tmpPlugins != null) {
View Full Code Here

            String[] configContent = readCurrentConfig();

            // Parse config
            ConfigParser parser = ConfigParser.getInstance();
            Configuration configuration = parser.parse(CURRENT_CONFIG, configContent);

            // Parse plugins
            List<Plugin> plugins = getPlugins();

            // Display configuration for edition
View Full Code Here

                LOGGER.log(Level.SEVERE, message);
            }

            // Parse config
            ConfigParser parser = ConfigParser.getInstance();
            Configuration configuration = parser.parse(configName, configContent);

            // Parse plugins
            List<Plugin> plugins = getPlugins();

            // Display configuration for edition
View Full Code Here

            }

            if (configContent != null) {
                // Parse config
                ConfigParser parser = ConfigParser.getInstance();
                Configuration configuration = parser.parse(configName, configContent);

                // Display configuration for edition
                if (mockPlugins == null) {
                    displayError("Load a plugin file before loading a configuration");
                } else {
View Full Code Here

        content[70] = "parameter:value:attribute = sys/tg_test/1/boolean_scalar";
        content[71] = "parameter:value:invalid_value = false";
        content[72] = "-";

        ConfigParser configParser = ConfigParser.getInstance();
        Configuration configuration = configParser.parse("configTest", content);

        assertNotNull(configuration);

        ActorSection actorSection = null;
        for (Section s : configuration.getSections()) {
            if (s instanceof ActorSection) {
                actorSection = (ActorSection) s;
            }
        }
View Full Code Here

TOP

Related Classes of fr.soleil.lib.flyscan.model.parsing.configuration.Configuration

Copyright © 2018 www.massapicom. 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.