private void onCollectionChange() { int nbElements = inputList.getTsCollection() != null ? inputList.getTsCollection().getCount() : 0; itemsLabel.setText( nbElements == 0 ? "No items" : nbElements + (nbElements < 2 ? " item" : " items")); runButton.setEnabled(nbElements != 0); clear(); getDocument().getElement().setTsCollection(inputList.getTsCollection().makeCopy()); }
public RevisionAnalysisTopComponent(WorkspaceItem<RevisionAnalysisDocument> item) { super(item); setName(getDocument().getDisplayName()); setToolTipText(Bundle.HINT_RevisionAnalysisTopComponent()); toolBarRepresentation = NbComponents.newInnerToolbar(); toolBarRepresentation.setFloatable(false); toolBarRepresentation.add(Box.createRigidArea(new Dimension(5, 0))); runButton = toolBarRepresentation.add( new AbstractAction("", DemetraUiIcon.COMPILE_16) { @Override public void actionPerformed(ActionEvent e) { start(); } }); runButton.setDisabledIcon(ImageUtilities.createDisabledIcon(runButton.getIcon())); runButton.setEnabled(false); addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(STATE_PROPERTY)) { onStateChange(); } } }); toolBarRepresentation.addSeparator(); itemsLabel = (JLabel) toolBarRepresentation.add(new JLabel("No items")); inputList = new JTsList(); inputList.addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { switch (evt.getPropertyName()) { case JTsList.COLLECTION_PROPERTY: onCollectionChange(); break; } } }); toolBarRepresentation.addSeparator(); JPopupMenu specPopup = new JPopupMenu(); final JButton specButton = (JButton) toolBarRepresentation.add( DropDownButtonFactory.createDropDownButton( ImageUtilities.loadImageIcon("ec/nbdemetra/sa/blog_16x16.png", false), specPopup)); specButton.setFocusPainted(false); specPopup .add(new ec.nbdemetra.ws.ui.SpecSelectionComponent()) .addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String p = evt.getPropertyName(); if (p.equals(ec.nbdemetra.ws.ui.SpecSelectionComponent.SPECIFICATION_PROPERTY) && evt.getNewValue() != null) { ISaSpecification spec = (ISaSpecification) evt.getNewValue(); curSpec.setSaSpecification(spec); defSpecLabel.setText(spec == null ? "" : spec.toLongString()); } else if (p.equals(ec.nbdemetra.ws.ui.SpecSelectionComponent.ICON_PROPERTY) && evt.getNewValue() != null) { specButton.setIcon(ImageUtilities.image2Icon((Image) evt.getNewValue())); } } }); specPopup.addPopupMenuListener( new PopupMenuAdapter() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { ((ec.nbdemetra.ws.ui.SpecSelectionComponent) ((JPopupMenu) e.getSource()).getComponent(0)) .setSpecification((ISaSpecification) curSpec.getSaSpecification()); } }); raView = new RevisionAnalysisTopComponent.RevisionAnalysisDocumentView(); raView.setDocument(getDocument().getElement()); loadingPanel = new LoadingPanel(raView); curSpec = getDocument().getElement().getSpecification().clone(); defSpecLabel = (JLabel) toolBarRepresentation.add(new JLabel()); defSpecLabel.setText( curSpec.getSaSpecification() == null ? "" : ((ISaSpecification) curSpec.getSaSpecification()).toLongString()); visualRepresentation = NbComponents.newJSplitPane(JSplitPane.VERTICAL_SPLIT, inputList, loadingPanel); visualRepresentation.setOneTouchExpandable(true); inputList.setTsCollection(getDocument().getElement().getInput()); setLayout(new BorderLayout()); add(toolBarRepresentation, BorderLayout.NORTH); add(visualRepresentation, BorderLayout.CENTER); refreshNode(); }