예제 #1
0
  /*
   * (non-Javadoc)
   *
   * @seeorg.eclipse.birt.chart.ui.swt.interfaces.ISeriesUIProvider#
   * validateAggregationType (org.eclipse.birt.chart.model.component.Series,
   * org.eclipse.birt.chart.model.data.SeriesDefinition,
   * org.eclipse.birt.chart.model.data.SeriesDefinition)
   */
  public boolean isValidAggregationType(
      Series series, SeriesDefinition orthSD, SeriesDefinition baseSD) {
    boolean isValidAgg = true;
    EList<Query> queries = series.getDataDefinition();
    for (int i : validationIndex(series)) {
      if (!isValidAgg) {
        break;
      }
      Query query = queries.get(i);
      boolean checked = false;
      String id =
          ChartWizard.Gatt_aggCheck_ID
              + series.eContainer().hashCode()
              + series.getDataDefinition().indexOf(query);
      ChartWizard.removeException(id);
      if (query.getGrouping() != null && query.getGrouping().isEnabled()) {
        checked = true;
        isValidAgg = isValidAggregation(query.getGrouping(), false, id);
      }

      if (!checked && orthSD.getGrouping() != null && orthSD.getGrouping().isEnabled()) {
        checked = true;
        isValidAgg = isValidAggregation(orthSD.getGrouping(), false, id);
      }

      if (!checked) {

        if (baseSD.getGrouping() != null && baseSD.getGrouping().isEnabled()) {
          isValidAgg = isValidAggregation(baseSD.getGrouping(), true, id);
        }
      }
    }
    return isValidAgg;
  }
예제 #2
0
  /**
   * Check if default aggregation and value series aggregation are valid for Gantt chart and show
   * warning message in UI.
   *
   * @param grouping
   * @param isCategoryGrouping
   * @param id error id for log
   * @return <code>true</code> if aggregation is valid.
   * @since 2.3
   */
  private boolean isValidAggregation(
      SeriesGrouping grouping, boolean isCategoryGrouping, String id) {
    if (grouping == null || !grouping.isEnabled()) {
      return true;
    }

    String aggName = grouping.getAggregateExpression();
    // Gantt chart only allow First, Last, Min and Max aggregations.
    if (!("First".equalsIgnoreCase(aggName) // $NON-NLS-1$
        || "Last".equalsIgnoreCase(aggName) // $NON-NLS-1$
        || "Min".equalsIgnoreCase(aggName) // $NON-NLS-1$
        || "Max".equalsIgnoreCase(aggName))) // $NON-NLS-1$
    {
      String aggPlace = ""; // $NON-NLS-1$
      if (isCategoryGrouping) {
        aggPlace =
            Messages.getString(
                "ChartUIUtil.TaskSelectData.Warning.CheckAgg.DefaultAggregate"); //$NON-NLS-1$
      } else {
        aggPlace =
            Messages.getString(
                "ChartUIUtil.TaskSelectData.Warning.CheckAgg.ValueSeriesAggregate"); //$NON-NLS-1$
      }
      ChartWizard.showException(
          id,
          Messages.getString(
                  "ChartUIUtil.TaskSelectData.Warning.CheckAgg.GanttChart") //$NON-NLS-1$
              + aggName
              + Messages.getString("ChartUIUtil.TaskSelectData.Warning.CheckAggAs") // $NON-NLS-1$
              + aggPlace
              + Messages.getString(
                  "ChartUIUtil.TaskSelectData.Warning.CheckAgg.Aggregation")); //$NON-NLS-1$

      return false;
    }

    return true;
  }
예제 #3
0
  public void launch(String filePath) {
    try {
      // add radar type
      Class<?> claexten =
          Class.forName(
              "org.eclipse.birt.chart.ui.swt.wizard.ChartUIExtensionsImpl"); //$NON-NLS-1$
      Field saTypes = claexten.getDeclaredField("saTypes"); // $NON-NLS-1$
      saTypes.setAccessible(true);
      saTypes.set(
          null,
          new String[] {
            "org.eclipse.birt.chart.ui.swt.type.BarChart",
            "org.eclipse.birt.chart.ui.swt.type.LineChart", //$NON-NLS-1$ //$NON-NLS-2$
            "org.eclipse.birt.chart.ui.swt.type.AreaChart",
            "org.eclipse.birt.chart.ui.swt.type.PieChart", //$NON-NLS-1$ //$NON-NLS-2$
            "org.eclipse.birt.chart.ui.swt.type.MeterChart",
            "org.eclipse.birt.chart.ui.swt.type.ScatterChart", //$NON-NLS-1$ //$NON-NLS-2$
            "org.eclipse.birt.chart.ui.swt.type.StockChart",
            "org.eclipse.birt.chart.ui.swt.type.GanttChart", //$NON-NLS-1$ //$NON-NLS-2$
            "org.eclipse.birt.chart.ui.swt.type.BubbleChart",
            "org.eclipse.birt.chart.ui.swt.type.DifferenceChart", //$NON-NLS-1$ //$NON-NLS-2$
            "org.eclipse.birt.chart.ui.swt.type.TubeChart",
            "org.eclipse.birt.chart.ui.swt.type.ConeChart", //$NON-NLS-1$ //$NON-NLS-2$
            "org.eclipse.birt.chart.ui.swt.type.PyramidChart", //$NON-NLS-1$
            "org.eclipse.birt.chart.examples.radar.ui.type.RadarChart" //$NON-NLS-1$
          });
      // add ui provider
      Field saSeriesUI = claexten.getDeclaredField("saSeriesUI"); // $NON-NLS-1$
      saSeriesUI.setAccessible(true);
      saSeriesUI.set(
          null,
          new String[] {
            "org.eclipse.birt.chart.ui.swt.series.SeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.AreaSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.BarSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.LineSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.MeterSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.PieSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.ScatterSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.StockSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.GanttSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.BubbleSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.ui.swt.series.DifferenceSeriesUIProvider", //$NON-NLS-1$
            "org.eclipse.birt.chart.examples.radar.ui.series.RadarSeriesUIProvider" //$NON-NLS-1$
          });

      // plugin settings
      Class<?> claps = Class.forName("org.eclipse.birt.chart.util.PluginSettings"); // $NON-NLS-1$
      Field saDataSetProcessors = claps.getDeclaredField("saDataSetProcessors"); // $NON-NLS-1$
      saDataSetProcessors.setAccessible(true);
      saDataSetProcessors.set(
          null,
          new String[] {
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.StockDataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.BubbleDataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.GanttDataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DifferenceDataSetProcessorImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.datafeed.DataSetProcessorImpl", //$NON-NLS-1$
          });

      Field saRenderers = claps.getDeclaredField("saRenderers"); // $NON-NLS-1$
      saRenderers.setAccessible(true);
      saRenderers.set(
          null,
          new String[] {
            null,
            "org.eclipse.birt.chart.extension.render.Area", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Bar", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Dial", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Line", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Pie", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Stock", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Scatter", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Bubble", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Gantt", //$NON-NLS-1$
            "org.eclipse.birt.chart.extension.render.Difference", //$NON-NLS-1$
            "org.eclipse.birt.chart.examples.radar.render.Radar" //$NON-NLS-1$
          });

      Field saSeries = claps.getDeclaredField("saSeries"); // $NON-NLS-1$
      saSeries.setAccessible(true);
      saSeries.set(
          null,
          new String[] {
            "org.eclipse.birt.chart.model.component.impl.SeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.AreaSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.BarSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.DialSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.LineSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.PieSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.StockSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.ScatterSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.BubbleSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.GanttSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.model.type.impl.DifferenceSeriesImpl", //$NON-NLS-1$
            "org.eclipse.birt.chart.examples.radar.model.type.impl.RadarSeriesImpl" //$NON-NLS-1$
          });
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (NoSuchFieldException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    // Create display
    Display.getDefault();

    // Set standalone mode rather than OSGI mode
    PlatformConfig config = new PlatformConfig();
    config.setProperty("STANDALONE", "true"); // $NON-NLS-1$ //$NON-NLS-2$
    ChartEngine.instance(config);
    final SampleStandardDataSheet ssd = new SampleStandardDataSheet();

    if (!UIHelper.isEclipseMode()) {
      // Registers the wizard task and the chart wizard
      try {
        TasksManager.instance().registerTask(TaskSelectType.class.getName(), new TaskSelectType());
        TasksManager.instance()
            .registerTask(
                TaskSelectData.class.getName(),
                new TaskSelectData() {
                  @Override
                  public void doPreview() {
                    super.doPreview();
                    ssd.refreshSampleDataPreiview();
                  }
                });
        TasksManager.instance()
            .registerTask(TaskFormatChart.class.getName(), new TaskFormatChart());
        String sChartTasks =
            TaskSelectType.class.getName()
                + ","
                + TaskSelectData.class.getName()
                + ","
                + TaskFormatChart.class.getName(); // $NON-NLS-1$ //$NON-NLS-2$
        TasksManager.instance()
            .registerWizard(ChartWizard.class.getName(), sChartTasks, ""); // $NON-NLS-1$
      } catch (Exception e) {
        WizardBase.displayException(e);
      }
    }

    Chart chart = null;
    Serializer serializer = null;
    final File chartFile = new File(filePath);

    // Reads the chart model
    InputStream is = null;
    try {
      serializer = SerializerImpl.instance();
      if (chartFile.exists()) {
        is = new FileInputStream(chartFile);
        chart = serializer.read(is);
      }
    } catch (Exception e) {
      // WizardBase.displayException( e );
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {

        }
      }
    }

    // Configures the chart wizard.
    final ChartWizard chartWizard = new ChartWizard();
    // Customized data provider and data sheet as below
    IDataServiceProvider dataProvider = new DefaultDataServiceProviderImpl();

    // Create context
    final ChartWizardContext context =
        new ChartWizardContext(
            chart,
            new SimpleUIServiceProviderImpl(),
            null,
            dataProvider,
            ssd,
            new ChartUIFactory());
    ((SimpleUIServiceProviderImpl) context.getUIServiceProvider())
        .setFormatSpecifierHandler(new FormatSpecifierHandler());
    ssd.setContext(context);

    // Use these methods to disable the UI you want.
    context.setEnabled(SUBTASK_TITLE, false);
    context.setEnabled(SUBTASK_LEGEND + BUTTON_LAYOUT, false);
    context.setEnabled(SUBTASK_SERIES_Y + BUTTON_LABEL, false);
    context.setEnabled(SUBTASK_SERIES_Y + BUTTON_CURVE, false);

    // Add predefined queries to select in data sheet
    context.addPredefinedQuery(
        QUERY_CATEGORY,
        new String[] {
          "row[\"abc\"]", "abc" // $NON-NLS-1$ //$NON-NLS-2$
        });
    context.addPredefinedQuery(QUERY_VALUE, new String[] {});

    context.setRtL(ChartUtil.isRightToLeftLocale(ULocale.getDefault()));

    // This array is for storing the latest chart data before pressing
    // apply button
    final Object[] applyData = new Object[1];

    // Add Apply button
    chartWizard.addCustomButton(
        new ApplyButtonHandler(chartWizard) {

          public void run() {
            super.run();
            // Save the data when applying
            applyData[0] = context.getModel().copyInstance();
          }
        });

    ChartLivePreviewThread livePreviewThread = new ChartLivePreviewThread(dataProvider);
    livePreviewThread.start();
    context.setLivePreviewThread(livePreviewThread);

    // Opens the wizard
    ChartWizardContext contextResult = (ChartWizardContext) chartWizard.open(context);

    OutputStream os = null;
    try {

      if (contextResult != null) {
        os = new FileOutputStream(chartFile);
        // Pressing Finish
        serializer.write(contextResult.getModel(), os);

      } else if (applyData[0] != null) {
        os = new FileOutputStream(chartFile);
        // Pressing Cancel but Apply was pressed before, so revert to
        // the point pressing Apply
        serializer.write((Chart) applyData[0], os);
      }
    } catch (Exception e) {
      WizardBase.displayException(e);
    } finally {
      if (os != null) {
        try {
          os.close();
        } catch (IOException e) {

        }
      }
    }
  }