/** * Implements the <tt>ListCellRenderer</tt> method. Returns this panel that has been configured to * display bundle name, version and description. * * @param table the parent table * @param value the value of the rendered cell * @param isSelected indicates if the rendered cell is selected * @param hasFocus indicates if the rendered cell has the focus * @param rowIndex the row index of the rendered cell * @param vColIndex the column index of the rendered cell * @return the rendering component */ public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) { Bundle bundle = (Bundle) value; Dictionary<?, ?> headers = bundle.getHeaders(); Object bundleName = headers.get(Constants.BUNDLE_NAME); Object bundleVersion = headers.get(Constants.BUNDLE_VERSION); Object bundleDescription = headers.get(Constants.BUNDLE_DESCRIPTION); Icon stateIcon = getStateIcon(bundle.getState()); if (bundleName != null) this.nameLabel.setText(bundleName.toString()); else this.nameLabel.setText("unknown"); if (bundleVersion != null) this.versionLabel.setText(bundleVersion.toString()); else this.versionLabel.setText(""); if (bundleDescription != null) this.descriptionLabel.setText(bundleDescription.toString()); else this.descriptionLabel.setText(""); if (stateIcon != null) this.stateLabel.setIcon(stateIcon); this.nameVersionPanel.remove(systemLabel); if (PluginManagerActivator.isSystemBundle(bundle)) this.nameVersionPanel.add(systemLabel); this.isSelected = isSelected; return this; }
public void setBundle(Bundle b) { try { MetaTypeInformation mtp = Activator.getMTP(b); jcmInfo.setProvider(mtp, b); } catch (Exception e) { e.printStackTrace(); Activator.log.error("Failed to get MetaTypeInformation from bundle " + b.getBundleId(), e); } }
private ToolAdapterOperatorDescriptor requestSelection() { ToolAdapterOperatorDescriptor selected = null; int selectedRow = operatorsTable.getSelectedRow(); if (selectedRow >= 0) { selected = ((OperatorsTableModel) operatorsTable.getModel()).getObjectAt(selectedRow); } else { SnapDialogs.showWarning(Bundle.MessageNoSelection_Text()); } return selected; }
/** * Invoked when an action occurs. * * @param e <tt>ActionEvent</tt>. */ public void actionPerformed(ActionEvent e) { Object tmp = skinSelector.getSelectedItem(); if (tmp != null) { if (tmp instanceof Bundle) { try { ((Bundle) tmp).uninstall(); } catch (BundleException ex) { } } } }
public static void showDialog(AppContext appContext, String helpID) { if (instance == null) { instance = new ToolAdaptersManagementDialog(appContext, Bundle.Dialog_Title(), helpID); } instance.show(); }
private JTable createPropertiesPanel() { DefaultTableModel model = new DefaultTableModel(1, 2) { @Override public boolean isCellEditable(int row, int column) { return column == 1; } }; model.setValueAt(Bundle.PathLabel_Text(), 0, 0); model.setValueAt(ToolAdapterIO.getUserAdapterPath(), 0, 1); model.addTableModelListener( l -> { String newPath = model.getValueAt(0, 1).toString(); File path = new File(newPath); if (!path.exists() && SnapDialogs.Answer.YES == SnapDialogs.requestDecision( "Path does not exist", "The path you have entered does not exist.\nDo you want to create it?", true, "Don't ask me in the future")) { if (!path.mkdirs()) { SnapDialogs.showError("Path could not be created!"); } } if (path.exists()) { File oldPath = ToolAdapterIO.getUserAdapterPath(); ToolAdapterOperatorDescriptor[] operatorDescriptors = ToolAdapterActionRegistrar.getActionMap() .values() .toArray( new ToolAdapterOperatorDescriptor [ToolAdapterActionRegistrar.getActionMap().values().size()]); for (ToolAdapterOperatorDescriptor descriptor : operatorDescriptors) { ToolAdapterActionRegistrar.removeOperatorMenu(descriptor); } ToolAdapterIO.setAdaptersPath(Paths.get(newPath)); if (!newPath.equals(oldPath.getAbsolutePath())) { Collection<ToolAdapterOpSpi> toolAdapterOpSpis = ToolAdapterIO.searchAndRegisterAdapters(); for (ToolAdapterOpSpi spi : toolAdapterOpSpis) { ToolAdapterActionRegistrar.registerOperatorMenu( (ToolAdapterOperatorDescriptor) spi.getOperatorDescriptor()); } refreshContent(); } } }); JTable table = new JTable(model); TableColumn labelColumn = table.getColumnModel().getColumn(0); labelColumn.setPreferredWidth((CHECK_COLUMN_WIDTH + LABEL_COLUMN_WIDTH) / 2); TableColumn pathColumn = table.getColumnModel().getColumn(1); pathColumn.setPreferredWidth(COLUMN_WIDTH); pathColumn.setCellEditor(new FileChooserCellEditor()); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setRowHeight(PATH_ROW_HEIGHT); table.setBorder(BorderFactory.createLineBorder(Color.black)); table.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) {} @Override public void focusLost(FocusEvent e) { Object source = e.getSource(); if (!table.equals(source)) { table.editingCanceled(new ChangeEvent(source)); table.clearSelection(); } } }); return table; }
private JPanel createButtonsPanel() { JPanel panel = new JPanel(new SpringLayout()); /** New adapter button */ panel.add( createButton( "New", TangoIcons.actions_document_new(TangoIcons.Res.R22), Bundle.ToolTipNewOperator_Text(), e -> { ToolAdapterOperatorDescriptor newOperatorSpi = new ToolAdapterOperatorDescriptor( ToolAdapterConstants.OPERATOR_NAMESPACE + "NewOperator", ToolAdapterOp.class, "NewOperator", null, null, null, null, null, null); ToolAdapterEditorDialog dialog = new ToolAdapterEditorDialog(appContext, newOperatorSpi, true); dialog.show(); refreshContent(); })); /** Duplicate adapter button */ panel.add( createButton( "Copy", TangoIcons.actions_edit_copy(TangoIcons.Res.R22), Bundle.ToolTipCopyOperator_Text(), e -> { ToolAdapterOperatorDescriptor operatorDesc = requestSelection(); if (operatorDesc != null) { String opName = operatorDesc.getName(); int newNameIndex = 0; while (GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpi(opName) != null) { newNameIndex++; opName = operatorDesc.getName() + ToolAdapterConstants.OPERATOR_GENERATED_NAME_SEPARATOR + newNameIndex; } ToolAdapterEditorDialog dialog = new ToolAdapterEditorDialog(appContext, operatorDesc, newNameIndex); dialog.show(); refreshContent(); } })); /** Edit adapter button */ panel.add( createButton( "Edit", TangoIcons.apps_accessories_text_editor(TangoIcons.Res.R22), Bundle.ToolTipEditOperator_Text(), e -> { ToolAdapterOperatorDescriptor operatorDesc = requestSelection(); if (operatorDesc != null) { ToolAdapterEditorDialog dialog = new ToolAdapterEditorDialog(appContext, operatorDesc, false); dialog.show(); refreshContent(); } })); /** Delete adapter button */ panel.add( createButton( "Delete", TangoIcons.actions_edit_clear(TangoIcons.Res.R22), Bundle.ToolTipDeleteOperator_Text(), e -> { ToolAdapterOperatorDescriptor operatorDescriptor = requestSelection(); if (operatorDescriptor != null) { if (SnapDialogs.Answer.YES == SnapDialogs.requestDecision( Bundle.MessageConfirmRemoval_TitleText(), Bundle.MessageConfirmRemoval_Text(), true, Bundle.MessageConfirmRemovalDontAsk_Text())) { if (operatorDescriptor.isFromPackage()) { SnapDialogs.showWarning( String.format( Bundle.MessagePackageModules_Text(), operatorDescriptor.getName())); } else { ToolAdapterActionRegistrar.removeOperatorMenu(operatorDescriptor); ToolAdapterIO.removeOperator(operatorDescriptor); } refreshContent(); } } })); /** Execute adapter button */ panel.add( createButton( "Run", TangoIcons.actions_media_playback_start(TangoIcons.Res.R22), Bundle.ToolTipExecuteOperator_Text(), e -> { ToolAdapterOperatorDescriptor operatorDesc = requestSelection(); if (operatorDesc != null) { // close(); final ToolAdapterExecutionDialog operatorDialog = new ToolAdapterExecutionDialog( operatorDesc, appContext, operatorDesc.getLabel()); operatorDialog.show(); } })); makeCompactGrid(panel, 1, 5, 0, 0, DEFAULT_PADDING, DEFAULT_PADDING); return panel; }