Пример #1
0
  protected void updateSelection() {
    final ReportSelectionModel selectionModel1 = getSelectionModel();
    if (selectionModel1 == null) {
      setEnabled(false);
      editedDataFactory = null;
      return;
    }

    final Object[] selectedObjects = selectionModel1.getSelectedElements();
    for (int i = 0; i < selectedObjects.length; i++) {
      final Object selectedObject = selectedObjects[i];
      if (selectedObject instanceof ReportQueryNode == false) {
        continue;
      }
      final ReportQueryNode queryNode = (ReportQueryNode) selectedObject;
      final DataFactory dataFactory = queryNode.getDataFactory();

      final DataFactoryMetaData metadata = dataFactory.getMetaData();
      if (metadata.isEditable()) {
        setEnabled(true);
        return;
      }
    }

    setEnabled(false);
  }
Пример #2
0
  public void performEdit(final DataFactory dataFactory, final String queryName)
      throws ReportDataFactoryException {
    final DataFactoryMetaData metadata = dataFactory.getMetaData();
    if (metadata.isEditable() == false) {
      return;
    }

    final DataSourcePlugin dataSourcePlugin = metadata.createEditor();
    final DataFactory storedFactory = dataFactory.derive();
    if (dataSourcePlugin.canHandle(dataFactory)) {
      final ReportRenderContext activeContext = getActiveContext();
      final AbstractReportDefinition report = activeContext.getReportDefinition();
      final boolean editingActiveQuery = contains(report.getQuery(), dataFactory.getQueryNames());

      final ReportDesignerDesignTimeContext designTimeContext =
          new ReportDesignerDesignTimeContext(getReportDesignerContext());
      editedDataFactory =
          dataSourcePlugin.performEdit(designTimeContext, dataFactory, queryName, null);
      if (editedDataFactory == null) {
        return;
      }

      final Window parentWindow = designTimeContext.getParentWindow();
      parentWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

      final CompoundDataFactory collection = (CompoundDataFactory) report.getDataFactory();
      final int dataFactoryCount = collection.size();
      for (int j = 0; j < dataFactoryCount; j++) {
        final DataFactory originalDataFactory = collection.getReference(j);
        if (originalDataFactory == dataFactory) {
          collection.remove(j);

          final DataFactory editedClone = editedDataFactory.derive();
          collection.add(j, editedDataFactory);
          activeContext
              .getUndo()
              .addChange(
                  ActionMessages.getString("EditQueryAction.Text"),
                  new DataSourceEditUndoEntry(j, storedFactory, editedClone));

          report.notifyNodeChildRemoved(originalDataFactory);
          report.notifyNodeChildAdded(editedDataFactory);

          parentWindow.setCursor(Cursor.getDefaultCursor());
          if (editingActiveQuery == false) {
            // if we are editing a query that is not the one the current report uses, do not mess
            // around with it.
            return;
          }

          final String[] editedQueries = editedDataFactory.getQueryNames();
          if (contains(report.getQuery(), editedQueries) == false) {
            report.setQuery(null);
          }
          return;
        }
      }

      throw new IllegalStateException();
    }
  }