private Component createChartSelectorButtonPane() { final ChartType[] types = ChartType.values(); final ButtonGroup buttonGroup = new ButtonGroup(); final JPanel buttonCarrier = new JPanel(); buttonCarrier.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); for (int i = 0; i < types.length; i++) { final ChartType type = types[i]; final SelectChartExpressionAction action = new SelectChartExpressionAction(type.getExpressionType()); editModel.getChartExpressionsModel().addListDataListener(action); final ActionToggleButton button = new ActionToggleButton(); button.putClientProperty("hideActionText", Boolean.TRUE); // NON-NLS button.setAction(action); button.setBorder(new EmptyBorder(0, 0, 0, 0)); buttonGroup.add(button); buttonCarrier.add(button); } final JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(buttonCarrier, BorderLayout.NORTH); return panel; }
/** * This method gets called when a bound property is changed. * * @param evt A PropertyChangeEvent object describing the event source and the property that has * changed. */ public void propertyChange(final PropertyChangeEvent evt) { if (LegacyChartEditModel.CHART_EXPRESSION_PROPERTY.equals(evt.getPropertyName()) == false) { return; } final Expression o = (Expression) evt.getNewValue(); if (o == null) { chartPropertiesTableModel.setData(EMPTY_EXPRESSION); dataSourceTabbedPane.setEnabledAt(1, false); dataSourceTabbedPane.setSelectedIndex(0); return; } chartPropertiesTableModel.setData(new Expression[] {o}); final ChartType type = ChartType.getTypeByChartExpression(o.getClass()); if (type == null) { dataSourceTabbedPane.setEnabledAt(1, false); dataSourceTabbedPane.setSelectedIndex(0); return; } dataSourceTabbedPane.setEnabledAt(1, type.getSecondaryDataSourceProperty() != null); }
public ChartEditingResult performEdit( final Element element, final ReportDesignerContext reportDesignerContext) throws CloneNotSupportedException { if (element == null) { throw new NullPointerException(); } if (reportDesignerContext == null) { throw new NullPointerException(); } if (LegacyChartsUtil.isLegacyChartElement(element) == false) { return null; } try { chartTable.setReportDesignerContext(reportDesignerContext); primaryDataSourceTable.setReportDesignerContext(reportDesignerContext); secondaryDataSourceTable.setReportDesignerContext(reportDesignerContext); chartPropertiesTableModel.setActiveContext(reportDesignerContext.getActiveContext()); primaryDataSourcePropertiesTableModel.setActiveContext( reportDesignerContext.getActiveContext()); secondaryDataSourcePropertiesTableModel.setActiveContext( reportDesignerContext.getActiveContext()); final Element editableElement = element.derive(); final Expression chartExpression = editableElement.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE); final Expression originalPrimaryDataSourceExpression; final Expression originalSecondaryDataSourceExpression; if (chartExpression != null) { originalPrimaryDataSourceExpression = extractPrimaryDatasource(element); originalSecondaryDataSourceExpression = extractSecondaryDatasource(element); editModel.setChartExpression(chartExpression.getInstance()); if (originalPrimaryDataSourceExpression != null) { editModel.setPrimaryDataSource(originalPrimaryDataSourceExpression.getInstance()); } else { editModel.setPrimaryDataSource(null); } if (originalSecondaryDataSourceExpression != null) { editModel.setSecondaryDataSource(originalSecondaryDataSourceExpression.getInstance()); } else { editModel.setSecondaryDataSource(null); } } else { editModel.setChartExpression(null); editModel.setPrimaryDataSource(null); editModel.setSecondaryDataSource(null); originalPrimaryDataSourceExpression = null; originalSecondaryDataSourceExpression = null; } if (editModel.getCurrentChartType() != null) { final ChartType chartType = editModel.getCurrentChartType(); if (editModel.getPrimaryDataSource() == null) { final Class dataSourceImplementation = chartType.getPreferredPrimaryDataSourceImplementation(); final ExpressionMetaData data = ExpressionRegistry.getInstance() .getExpressionMetaData(dataSourceImplementation.getName()); editModel.getPrimaryDataSourcesModel().setSelectedItem(data); } if (editModel.getSecondaryDataSource() == null) { final Class dataSourceImplementation = chartType.getPreferredSecondaryDataSourceImplementation(); if (dataSourceImplementation != null) { final ExpressionMetaData data = ExpressionRegistry.getInstance() .getExpressionMetaData(dataSourceImplementation.getName()); editModel.getSecondaryDataSourcesModel().setSelectedItem(data); } } } if (performEdit() == false) { return null; } secondaryDataSourceTable.stopEditing(); primaryDataSourceTable.stopEditing(); chartTable.stopEditing(); return new ChartEditingResult( chartExpression, originalPrimaryDataSourceExpression, originalSecondaryDataSourceExpression, editModel.getChartExpression(), editModel.getPrimaryDataSource(), editModel.getSecondaryDataSource()); } finally { chartTable.setReportDesignerContext(null); primaryDataSourceTable.setReportDesignerContext(null); secondaryDataSourceTable.setReportDesignerContext(null); chartPropertiesTableModel.setActiveContext(null); primaryDataSourcePropertiesTableModel.setActiveContext(null); secondaryDataSourcePropertiesTableModel.setActiveContext(null); } }