Example usage for javax.swing.event ListSelectionListener ListSelectionListener

List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener

Introduction

In this page you can find the example usage for javax.swing.event ListSelectionListener ListSelectionListener.

Prototype

ListSelectionListener

Source Link

Usage

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

public PanboxClientGUI(final PanboxClient client) {
    this.client = client;

    this.shareModel = client.getShareList();
    this.contactModel = client.getContactList();
    this.deviceModel = client.getDeviceList();

    initComponents();/*  ww  w.j  a  v a2 s .c  o m*/

    ActionListener changesDetectedActionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setSettingsChangesDetected();
        }
    };

    DocumentListener changesDetectedDocumentListener = new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            setSettingsChangesDetected();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            setSettingsChangesDetected();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {

        }
    };

    dropboxSettingsPanel = new DropboxSettingsPanel(changesDetectedActionListener,
            changesDetectedDocumentListener);

    initSettingsConfig();

    // set the icon
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image img = kit.createImage(getClass().getResource("panbox-icon-big.png"));
    setIconImage(img);

    // set the default locale for popup messages
    JOptionPane.setDefaultLocale(Settings.getInstance().getLocale());

    // Hide these for now. Do we still need this?
    syncStatusLabel.setVisible(false);
    syncStatusTextField.setVisible(false);

    cspInfoTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // NOI18N

    shareList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            refreshShare();
        }
    });
    shareList.setSelectedIndex(0); // always try to select first share

    enableDisableAddDeviceContactForShare();

    addressbookList.addListSelectionListener(new ListSelectionListener() {

        private DocumentListener firstNameFieldDocListener = new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }

            public void changed() {
                if (!firstNameTextField.getText().equals(contact.getFirstName()) && !unsavedContactChanges) {
                    setContactChangesDetected();
                }
            }
        };
        private DocumentListener lastNameFieldDocListener = new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }

            public void changed() {
                if (!lastNameTextField.getText().equals(contact.getName()) && !unsavedContactChanges) {
                    setContactChangesDetected();
                }
            }
        };
        private ListSelectionListener cspListSelectionListener = new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                int selectedIndex = cspInfoTable.getSelectedRow();
                int max = ((CSPTableModel) cspInfoTable.getModel()).getMax();
                if (selectedIndex != -1 && selectedIndex < max) {
                    removeCSPInfoButton.setEnabled(true);
                } else {
                    removeCSPInfoButton.setEnabled(false);
                }
            }
        };

        boolean manuallySetSelection = false;

        @Override
        public void valueChanged(ListSelectionEvent e) {
            final List<PanboxGUIContact> selected = addressbookList.getSelectedValuesList();

            firstNameTextField.getDocument().removeDocumentListener(firstNameFieldDocListener);
            lastNameTextField.getDocument().removeDocumentListener(lastNameFieldDocListener);
            cspInfoTable.getSelectionModel().removeListSelectionListener(cspListSelectionListener);

            if (!manuallySetSelection) {
                if (!uneditedCSPsExist()) {
                    if (unsavedContactChanges) {
                        int saveUnchanged = JOptionPane.showConfirmDialog(null,
                                bundle.getString("PanboxClientGUI.unsavedChangesToContact"), // NOI18N
                                bundle.getString("PanboxClientGUI.panboxMessage"), // NOI18N
                                JOptionPane.YES_NO_CANCEL_OPTION);
                        if (saveUnchanged == JOptionPane.YES_OPTION) {
                            saveContactChanges();
                            refreshContact();
                            resetContactApplyDiscardButtons();
                        } else if (saveUnchanged == JOptionPane.CANCEL_OPTION) {
                            manuallySetSelection = true;
                            int previousIndex = e.getFirstIndex() == addressbookList.getSelectedIndex()
                                    ? e.getLastIndex()
                                    : e.getFirstIndex();
                            addressbookList.setSelectedIndex(previousIndex);
                        } else {
                            refreshContact();
                            resetContactApplyDiscardButtons();
                        }
                        unsavedContactChanges = false;
                    }

                    int selectedIndex = addressbookList.getSelectedIndex();
                    if (selectedIndex != -1) {
                        // enable Buttons
                        removeContactButton.setEnabled(true);
                        exportContactButton.setEnabled(true);

                        // refresh contact infos
                        contact = contactModel.getElementAt(selectedIndex);
                        contacts = selected;
                        firstNameTextField.setText(contact.getFirstName());
                        lastNameTextField.setText(contact.getName());
                        emailTextField.setText(contact.getEmail());
                        cspInfoTable.setModel(contact.generateCspInfoTableModel());
                        cspInfoTable.getSelectionModel().addListSelectionListener(cspListSelectionListener);

                        // show certificate info
                        encKeyFprintTextField.setText(contact.getCertEncFingerprint());
                        signKeyFprintTextField.setText(contact.getCertSignFingerprint());
                        validFromUntilLabel.setText(bundle.getString("valid.from") + " " + contact.getFromDate()
                                + " " + bundle.getString("valid.to") + " " + contact.getUntilDate());

                        // disable apply and discard buttons when contact
                        // selection
                        // changes
                        contactApplyButton.setEnabled(false);
                        contactDiscardButton.setEnabled(false);

                        // disable csp add button when no further csps are
                        // available to add
                        if (contact.getAvailableCSPs() > 0) {
                            addCSPInfoButton.setEnabled(true);
                        } else {
                            addCSPInfoButton.setEnabled(false);
                        }
                        removeCSPInfoButton.setEnabled(false);

                        if (contact instanceof PanboxMyContact) {
                            firstNameTextField.setEnabled(false);
                            lastNameTextField.setEnabled(false);
                            removeContactButton.setEnabled(false);
                            contactVerificationStatusCheckBox.setEnabled(false);
                        } else {
                            firstNameTextField.setEnabled(true);
                            lastNameTextField.setEnabled(true);
                            removeContactButton.setEnabled(true);
                            firstNameTextField.getDocument().addDocumentListener(firstNameFieldDocListener);
                            lastNameTextField.getDocument().addDocumentListener(lastNameFieldDocListener);
                            contactVerificationStatusCheckBox.setEnabled(true);
                        }

                    } else {
                        // disable export and remove button when no item is
                        // selected
                        removeContactButton.setEnabled(false);
                        exportContactButton.setEnabled(false);
                    }
                } else {
                    manuallySetSelection = true;
                    int previousIndex = e.getFirstIndex() == addressbookList.getSelectedIndex()
                            ? e.getLastIndex()
                            : e.getFirstIndex();
                    addressbookList.setSelectedIndex(previousIndex);
                }
            } else {
                manuallySetSelection = false;
            }

            if (contact.isVerified()) {
                contactVerificationStatusCheckBox.setSelected(true);
                contactVerificationStatusCheckBox.setText(bundle.getString("PanboxClientGUI.contact.verified"));
            } else {
                contactVerificationStatusCheckBox.setSelected(false);
                contactVerificationStatusCheckBox.setText(bundle.getString("PanboxClientGUI.contact.verified"));
            }
        }
    });
    addressbookList.setSelectedIndex(0); // always try to select first
    // contact

    // contact
    firstNameTextField.setDisabledTextColor(Color.BLACK);
    lastNameTextField.setDisabledTextColor(Color.BLACK);
    emailTextField.setDisabledTextColor(Color.BLACK);
    encKeyFprintTextField.setDisabledTextColor(Color.BLACK);
    signKeyFprintTextField.setDisabledTextColor(Color.BLACK);

    deviceList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int selected = deviceList.getSelectedIndex();
            if (!e.getValueIsAdjusting() && selected != -1) {
                device = deviceModel.getElementAt(selected);

                deviceKeyFprintTextField.setText(device.getDevicePubKeyFingerprint());

                deviceShareList.setModel(client.getDeviceShares(device));

                checkIfRemoveDeviceShouldBeEnabled();
            }
        }
    });
    deviceList.setSelectedIndex(0); // always try to select first device

    checkIfRemoveDeviceShouldBeEnabled();

    // expert mode visible/invisible
    expertModeCheckBoxActionPerformed(null);

    languageComboBox.addActionListener(changesDetectedActionListener);
    expertModeCheckBox.addActionListener(changesDetectedActionListener);
    networkAddressComboBox.addActionListener(changesDetectedActionListener);
    networkInterfaceComboBox.addActionListener(changesDetectedActionListener);

    panboxFolderTextField.getDocument().addDocumentListener(changesDetectedDocumentListener);
    settingsFolderTextField.getDocument().addDocumentListener(changesDetectedDocumentListener);

    // disable settings apply and discard buttons
    settingsApplyButton.setEnabled(false);
    settingsRevertButton.setEnabled(false);

    // TODO: add action and document listeners to the csp settings after it
    // has been fixed (see trac ticket #139)

    // Disable device pairing for SLAVE devices and enable the click for MASTER devices!
    if (Settings.getInstance().isSlave()) {
        addDeviceButton.setEnabled(false);
        addDeviceButton.setToolTipText(bundle.getString("client.disabledPairingSlave"));
    } else {
        addDeviceButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                addDeviceButtonMousePressed(evt);
            }
        });
    }

    if (OS.getOperatingSystem().isWindows()) {
        panboxFolderLabel.setText(bundle.getString("client.settings.panboxDrive")); // NOI18N

        panboxFolderChooseButton.setVisible(false);
    }
}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

public void setOnselect(final String select) {
    selectionListener = new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            if (event.getValueIsAdjusting() == true) {
                return;
            }//from w w  w  . jav  a  2  s.  c  o  m
            invoke(select, new Object[] { new Integer(table.getSelectedRow()) });
        }
    };

    if (table != null) {
        table.getSelectionModel().addListSelectionListener(selectionListener);
    }

    treeSelectionListener = new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            if (tree != null) {
                invoke(select, new Object[] { tree.getSelectionRows()[0] });
            }
        }
    };

    if (tree != null) {
        tree.getSelectionModel().addTreeSelectionListener(treeSelectionListener);
    }
}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

@Override
public void layout() {

    XulComponent primaryColumn = this.getElementByXPath("//treecol[@primary='true']"); //$NON-NLS-1$
    XulComponent isaContainer = this.getElementByXPath("treechildren/treeitem[@container='true']"); //$NON-NLS-1$

    isHierarchical = (primaryColumn != null) || (isaContainer != null);

    if (isHierarchical) {
        tree = new JTree();
        if (treeSelectionListener != null) {
            tree.getSelectionModel().addTreeSelectionListener(treeSelectionListener);
        }//from   w  w  w  . j av a 2s.  co m
        tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                SwingTree.this.changeSupport.firePropertyChange("selectedRows", null, //$NON-NLS-1$
                        SwingTree.this.getSelectedRows());
                SwingTree.this.changeSupport.firePropertyChange("absoluteSelectedRows", null, //$NON-NLS-1$
                        SwingTree.this.getAbsoluteSelectedRows());
                SwingTree.this.fireSelectedItem();
            }
        });
    } else {
        table = new ScrollableJTable();
        if (selectionListener != null) {
            table.getSelectionModel().addListSelectionListener(selectionListener);
        }
        table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent event) {
                if (event.getValueIsAdjusting() == true) {
                    return;
                }
                SwingTree.this.changeSupport.firePropertyChange("selectedRows", null, //$NON-NLS-1$
                        SwingTree.this.getSelectedRows());
                SwingTree.this.fireSelectedItem();

            }
        });
    }

    JComponent comp = (table != null ? table : tree);
    ToolTipManager.sharedInstance().unregisterComponent(comp);
    if (table != null) {
        ToolTipManager.sharedInstance().unregisterComponent(table.getTableHeader());

        table.setRowHeight(18);
        scrollpane = new JScrollPane(table);
        setupTable();

    } else {
        setupTree();
        scrollpane = new JScrollPane(tree);
    }

    setManagedObject(scrollpane.getViewport());
}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private void setupTable() {

    // generate table object based on TableModel and TableColumnModel

    // if(tableModel == null){
    tableModel = new XulTableModel(this);
    // }/*from  ww w  . j a v  a  2 s  .c  o  m*/
    table.setModel(this.tableModel);
    this.setSeltype(getSeltype());

    updateColumnModel();

    initialized = true;

    table.addComponentListener(new ComponentListener() {
        public void componentHidden(ComponentEvent arg0) {
        }

        public void componentMoved(ComponentEvent e) {
        }

        public void componentShown(ComponentEvent e) {
        }

        public void componentResized(ComponentEvent e) {
            calcColumnWidths();
        }
    });

    // Property change on selections
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent event) {
            if (event.getValueIsAdjusting() == true) {
                return;
            }
            SwingTree.this.changeSupport.firePropertyChange("selectedRows", null, //$NON-NLS-1$
                    SwingTree.this.getSelectedRows());
            SwingTree.this.changeSupport.firePropertyChange("absoluteSelectedRows", null, //$NON-NLS-1$
                    SwingTree.this.getAbsoluteSelectedRows());
        }
    });

    table.getTableHeader().setReorderingAllowed(this.isEnableColumnDrag());

    this.setDisabled(this.isDisabled());
}

From source file:org.piraso.ui.base.ContextMonitorDialog.java

/**
 * Creates new form ContextMonitorDialog
 *///from  ww w  . j  a  v  a2 s  .co m
public ContextMonitorDialog() {
    super();
    setTitle("Manage Monitors");
    initComponents();
    initPreferences();
    addButtonRefreshListeners();

    lstMonitors.setModel(listModel);
    cboHost.setModel(cboModel);

    lstMonitors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lstMonitors.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            initSelection((String) lstMonitors.getSelectedValue());
        }
    });

    refresh();
    setLocationRelativeTo(getOwner());
}

From source file:org.piraso.ui.base.ProfilesDialog.java

/**
 * Creates new form ProfilesDialog/* ww  w  . ja  v  a2 s .c  om*/
 */
public ProfilesDialog() {
    super();
    setTitle("Manage Profiles");

    initComponents();
    initTable();
    addButtonRefreshListeners();

    lstProfiles.setModel(listModel);
    lstProfiles.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lstProfiles.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            initSelection((String) lstProfiles.getSelectedValue());
        }
    });

    refresh();
    setLocationRelativeTo(getOwner());
}

From source file:org.pmedv.blackboard.components.PartView.java

protected void initializeComponents() {

    setLayout(new BorderLayout());

    partPanel = new PartPanel();
    partBusyPanel = new JBusyComponent<PartPanel>(partPanel);

    setSize(new Dimension(900, 650));

    textArea = new RSyntaxTextArea();
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
    RTextScrollPane textScrollPane = new RTextScrollPane(textArea);

    CompletionProvider provider = createCompletionProvider();
    AutoCompletion ac = new AutoCompletion(provider);
    ac.install(textArea);/*  ww  w  .  j a va  2  s  .  c om*/

    JPopupMenu popup = textArea.getPopupMenu();
    popup.addSeparator();
    popup.add(new JMenuItem(new SaveAction()));

    tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    tabbedPane.addTab("Parts", partBusyPanel);
    tabbedPane.addTab("Part Editor", textScrollPane);
    tabbedPane.setEnabledAt(1, false);
    add(tabbedPane, BorderLayout.CENTER);

    tablePopupMenu = new JPopupMenu();

    // We do the part loading in background and display a busy panel while loading

    SwingWorker<ArrayList<Part>, Void> w = new SwingWorker<ArrayList<Part>, Void>() {

        @Override
        protected ArrayList<Part> doInBackground() {
            partBusyPanel.setBusy(true);
            try {
                return AppContext.getContext().getBean(PartFactory.class).getAvailableParts();
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
                return new ArrayList<Part>();
            }
        }

        @Override
        protected void done() {
            log.info("Done loading parts.");
            try {
                model = new PartTableModel(get());
                partPanel.getPartTable().setModel(model);
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
            }
            partBusyPanel.setBusy(false);
            partPanel.transferFocus();
        }
    };

    partPanel.getPartTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            JXTable table = partPanel.getPartTable();
            int[] rows = table.getSelectedRows();
            if (rows.length == 1) {
                if (model == null)
                    return;
                Part selectedPart = model.getParts().get(table.convertRowIndexToModel(rows[0]));
                currentPart = selectedPart;
                selectedRow = table.convertRowIndexToModel(rows[0]);
                partPanel.getImageLabel().setIcon(new ImageIcon(selectedPart.getImage()));
                partPanel.getImageLabel().setText(null);
                partPanel.getPartNameField().setText(selectedPart.getName());
                partPanel.getDescriptionPane().setText(selectedPart.getDescription());
                partPanel.getPackageTypeField().setText(selectedPart.getPackageType());
                partPanel.getAuthorField().setText(selectedPart.getAuthor());
                partPanel.getLicenseField().setText(selectedPart.getLicense());
                tabbedPane.setEnabledAt(1, true);
                textArea.setText(selectedPart.getXmlContent());
            } else {
                currentPart = null;
                partPanel.getImageLabel().setText(resources.getResourceByKey("PartDialog.selectmsg"));
                partPanel.getImageLabel().setIcon(null);
                tabbedPane.setEnabledAt(1, false);
                textArea.setText("");
            }
        }
    });

    partPanel.getPartTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            handlePopupTrigger(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            handlePopupTrigger(e);
        }
    });

    tablePopupMenu.add(AppContext.getContext().getBean(DeletePartCommand.class));

    // this is the filter configuration for the filter text box on the top
    PartFilter filter = new PartFilter(partPanel.getPartTable());
    BindingGroup filterGroup = new BindingGroup();
    // bind filter JTextBox's text attribute to part tables filterString
    // attribute
    filterGroup.addBinding(Bindings.createAutoBinding(READ, partPanel.getFilterPanel().getFilterTextField(),
            BeanProperty.create("text"), filter, BeanProperty.create("filterString")));
    filterGroup.bind();
    w.execute();

}

From source file:org.pmedv.blackboard.dialogs.PartDialog.java

@Override
protected void initializeComponents() {

    partPanel = new PartPanel();
    partBusyPanel = new JBusyComponent<PartPanel>(partPanel);

    setSize(new Dimension(900, 750));

    textArea = new RSyntaxTextArea();
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
    RTextScrollPane textScrollPane = new RTextScrollPane(textArea);

    CompletionProvider provider = createCompletionProvider();
    AutoCompletion ac = new AutoCompletion(provider);
    ac.install(textArea);//  ww w.  j a v a 2s  .co  m

    JPopupMenu popup = textArea.getPopupMenu();
    popup.addSeparator();
    popup.add(new JMenuItem(new SaveAction()));

    tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    tabbedPane.addTab("Parts", partBusyPanel);
    tabbedPane.addTab("Part Editor", textScrollPane);
    tabbedPane.setEnabledAt(1, false);
    getContentPanel().add(tabbedPane);

    tablePopupMenu = new JPopupMenu();

    // We do the part loading in background and display a busy panel while loading

    SwingWorker<ArrayList<Part>, Void> w = new SwingWorker<ArrayList<Part>, Void>() {

        @Override
        protected ArrayList<Part> doInBackground() {
            partBusyPanel.setBusy(true);
            try {
                return AppContext.getContext().getBean(PartFactory.class).getAvailableParts();
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
                return new ArrayList<Part>();
            }
        }

        @Override
        protected void done() {
            log.info("Done loading parts.");
            try {
                model = new PartTableModel(get());
                partPanel.getPartTable().setModel(model);
            } catch (Exception e) {
                ErrorUtils.showErrorDialog(e);
            }
            partBusyPanel.setBusy(false);
            partPanel.transferFocus();
        }
    };

    getOkButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JXTable table = partPanel.getPartTable();
            result = OPTION_OK;
            selectedParts = new ArrayList<Part>();
            int rows[] = partPanel.getPartTable().getSelectedRows();
            try {
                for (int i = 0; i < rows.length; i++) {
                    selectedParts.add(AppContext.getContext().getBean(PartFactory.class).createPart(
                            model.getParts().get(table.convertRowIndexToModel(rows[i])).getFilename()));
                }
            } catch (Exception e1) {
                ErrorUtils.showErrorDialog(e1);
            }
            setVisible(false);
        }
    });

    getCancelButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            result = OPTION_CANCEL;
            setVisible(false);
        }
    });

    getNewButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            AppContext.getContext().getBean(CreatePartCommand.class).execute(e);
        }
    });

    partPanel.getPartTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            JXTable table = partPanel.getPartTable();
            int[] rows = table.getSelectedRows();
            if (rows.length == 1) {
                if (model == null)
                    return;
                Part selectedPart = model.getParts().get(table.convertRowIndexToModel(rows[0]));
                currentPart = selectedPart;
                selectedRow = table.convertRowIndexToModel(rows[0]);
                partPanel.getImageLabel().setIcon(new ImageIcon(selectedPart.getImage()));
                partPanel.getImageLabel().setText(null);
                partPanel.getPartNameField().setText(selectedPart.getName());
                partPanel.getDescriptionPane().setText(selectedPart.getDescription());
                partPanel.getPackageTypeField().setText(selectedPart.getPackageType());
                partPanel.getAuthorField().setText(selectedPart.getAuthor());
                partPanel.getLicenseField().setText(selectedPart.getLicense());
                tabbedPane.setEnabledAt(1, true);
                textArea.setText(selectedPart.getXmlContent());
            } else {
                currentPart = null;
                partPanel.getImageLabel().setText(resources.getResourceByKey("PartDialog.selectmsg"));
                partPanel.getImageLabel().setIcon(null);
                tabbedPane.setEnabledAt(1, false);
                textArea.setText("");
            }
        }
    });

    tabbedPane.addChangeListener(new ChangeListener() {
        // This method is called whenever the selected tab changes
        public void stateChanged(ChangeEvent evt) {
            JTabbedPane pane = (JTabbedPane) evt.getSource();
            int index = pane.getSelectedIndex();
            if (index == 0) {
                getTitleLabel().setText(title);
                getSubTitleLabel().setText(subTitle);
            } else {
                getTitleLabel().setText(editTitle);
                getSubTitleLabel().setText(editSubTitle + " : " + currentPart.getName());
            }
        }
    });

    partPanel.getPartTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            handlePopupTrigger(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            handlePopupTrigger(e);
        }
    });

    tablePopupMenu.add(ctx.getBean(DeletePartCommand.class));

    // this is the filter configuration for the filter text box on the top
    PartFilter filter = new PartFilter(partPanel.getPartTable());
    BindingGroup filterGroup = new BindingGroup();
    // bind filter JTextBox's text attribute to part tables filterString
    // attribute
    filterGroup.addBinding(Bindings.createAutoBinding(READ, partPanel.getFilterPanel().getFilterTextField(),
            BeanProperty.create("text"), filter, BeanProperty.create("filterString")));
    filterGroup.bind();
    w.execute();

}

From source file:org.rimudb.editor.DescriptorEditor.java

/**
 * Build the panel/*  w  w  w .  j av a 2  s .  c o  m*/
 */
private JPanel createColumnTablePanel() {
    JPanel columnPanel = new JPanel();
    columnPanel.setLayout(new BoxLayout(columnPanel, BoxLayout.Y_AXIS));

    // Create the property table panel
    propertyModel = new PropertyTableModel();

    // Add a listener to set the changed state
    propertyModel.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            markChanged();

            if (e instanceof PropertyTableModelEvent) {
                PropertyTableModelEvent ptme = (PropertyTableModelEvent) e;

                // If the columnName column was changed then check it isn't
                // a PK
                if (ptme.getColumn() == 1) {

                    String beforeColumnName = (String) ptme.getBeforeValue();
                    String afterColumnName = (String) ptme.getAfterValue();

                    // Is the field entry in the list of primary keys?
                    for (int i = 0; i < pkListModel.getSize(); i++) {
                        String pkColumnName = (String) pkListModel.get(i);
                        // If it's found then remove it
                        if (beforeColumnName.equals(pkColumnName)) {
                            pkListModel.set(i, afterColumnName);
                            break;
                        }
                    }

                }

            }
        }
    });

    table = new ATable(getPropertyModel());
    table.setName("ColumnTable");
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = table.getSelectedRowCount();
            removeColumnBtn.setEnabled(selectedRowCount > 0);
            moveUpBtn.setEnabled(selectedRowCount > 0);
            moveDownBtn.setEnabled(selectedRowCount > 0);
        }
    });
    table.setTransferHandler(new TransferHandler() {

        public int getSourceActions(JComponent c) {
            return COPY;
        }

        protected Transferable createTransferable(JComponent c) {
            ATable columnTable = (ATable) c;
            int row = columnTable.getSelectedRow();
            String columnName = getPropertyModel().getRow(row).getColumnName();
            return new StringSelection(columnName);
        }
    });
    table.setDragEnabled(true);

    JScrollPane sp = new JScrollPane(table);
    sp.setMaximumSize(new Dimension(Short.MAX_VALUE, 325));
    sp.setPreferredSize(new Dimension(Short.MAX_VALUE, 325));
    sp.setMinimumSize(new Dimension(Short.MAX_VALUE, 325));

    JComboBox typeCB = new JComboBox(DatabaseTypes.getAllTypes());
    typeCB.setEditable(false);

    javax.swing.table.TableColumn typeColumn = table.getColumnModel().getColumn(2);
    typeColumn.setCellEditor(new DefaultCellEditor(typeCB));

    // Create the popup menu and set it on the table
    propertyPopup = new TablePopupMenu(this, table);
    table.addMouseListener(propertyPopup);
    sp.addMouseListener(propertyPopup);
    sp.setAlignmentX(LEFT_ALIGNMENT);

    columnPanel.add(sp);

    columnPanel.add(Box.createVerticalStrut(10));

    JLabel pkLabel = new JLabel("Primary Key Columns", SwingConstants.LEFT);
    pkLabel.setAlignmentX(LEFT_ALIGNMENT);
    columnPanel.add(pkLabel);

    pkListModel = new DefaultListModel();
    pkListModel.addListDataListener(new ListDataListener() {
        public void intervalRemoved(ListDataEvent e) {
            markChanged();
        }

        public void intervalAdded(ListDataEvent e) {
            markChanged();
        }

        public void contentsChanged(ListDataEvent e) {
            markChanged();
        }
    });

    pkList = new JList(pkListModel);
    pkList.setName("pkList");
    pkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pkList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int selectedRowCount = pkList.getSelectedIndex();
            removePkBtn.setEnabled(selectedRowCount > -1);
        }
    });
    pkList.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            if (dl.getIndex() == -1) {
                return false;
            }
            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            if (!info.isDrop()) {
                return false;
            }

            // Check for String flavor
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                displayDropLocation("List doesn't accept a drop of this type.");
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            DefaultListModel listModel = (DefaultListModel) pkList.getModel();
            int index = dl.getIndex();

            // Get the string that is being dropped.
            Transferable t = info.getTransferable();
            String data;
            try {
                data = (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }

            // If this is a copy action then check we don't already have that String
            if (info.getDropAction() == COPY && listModel.indexOf(data) > -1) {
                displayDropLocation("The column " + data + " is already a primary key");
                return false;
            }

            // Perform the actual import. 
            if (dl.isInsert()) {
                int oldIndex = listModel.indexOf(data);
                if (oldIndex < index) {
                    listModel.add(index, data);
                    listModel.remove(oldIndex);
                } else {
                    listModel.remove(oldIndex);
                    listModel.add(index, data);
                }
            } else {
                // Don't handle replacements
            }
            return true;
        }

        public int getSourceActions(JComponent c) {
            return MOVE;
        }

        protected Transferable createTransferable(JComponent c) {
            JList list = (JList) c;
            Object[] values = list.getSelectedValues();

            StringBuffer buff = new StringBuffer();

            for (int i = 0; i < values.length; i++) {
                Object val = values[i];
                buff.append(val == null ? "" : val.toString());
                if (i != values.length - 1) {
                    buff.append("\n");
                }
            }
            return new StringSelection(buff.toString());
        }
    });
    pkList.setDropMode(DropMode.INSERT);
    pkList.setDragEnabled(true);

    JScrollPane pkScrollPanel = new JScrollPane(pkList);
    pkScrollPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 100));
    pkScrollPanel.setAlignmentX(LEFT_ALIGNMENT);

    columnPanel.add(pkScrollPanel);

    return columnPanel;
}

From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java

public DialogVisualElement(Lookup lkp) {
    obj = lkp.lookup(DialogDataObject.class);
    assert obj != null;

    undoRedo = new UndoRedo.Manager();
    undoRedo.addChangeListener(new ChangeListener() {

        @Override/*from  w w w . j av a 2  s.  co  m*/
        public void stateChanged(ChangeEvent e) {
            obj.setModified(true);
        }
    });
    initComponents();

    contentPanel = new JPanel() {
        @Override
        public void paint(Graphics g) {
            super.paint(g);
            for (JComponent c : overlayComponents) {
                c.setBounds(this.getBounds());
                c.paint(g);
            }
        }
    };
    contentPanel.setLayout(new VerticalFlowLayout(GAP_Y * 2));
    contentPanel.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (!e.isConsumed()) {
                requestFocus();
                callback.requestActive();
            }
        }
    });

    personsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            personsListSelectionEvent();
        }
    });
    removeButton.setEnabled(false);
    Action editNames = new EditListAction();
    ListAction ls = new ListAction(personsList, editNames);
    personsList.getModel().addListDataListener(new ListDataListener() {
        @Override
        public void intervalAdded(ListDataEvent e) {
            updatePersons();
        }

        @Override
        public void intervalRemoved(ListDataEvent e) {
            updatePersons();
        }

        @Override
        public void contentsChanged(ListDataEvent e) {
            updatePersons();
        }
    });

    setupVisuals();

    contentParent = new JPanel();
    contentParent.setLayout(new BorderLayout());
    //      contentPanel.setBounds(contentPanel.getBounds());
    //      contentParent.setBounds(contentPanel.getBounds());
    contentParent.add(contentPanel);
    scrollPane.setViewportView(contentParent);
    jumpListener = new JumpListener(this);
    dropListener = new DropListener(this);
    DropTarget dt = new DropTarget(contentParent, dropListener);
    contentParent.setDropTarget(dt);

    obj.getPrimaryFile().addFileChangeListener(new FileChangeAdapter() {

        @Override
        public void fileChanged(FileEvent fe) {
            refresh();
        }

    });
    obj.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName()) && callback != null) {
                if (obj.isModified()) {
                    callback.updateTitle("<html><b>" + obj.getName() + "</b></html>");
                } else {
                    callback.updateTitle("<html>" + obj.getName() + "</html>");
                }
            }
        }
    });
}