コード例 #1
0
  private Object performQuery(
      final ReportFormulaContext context,
      final String query,
      final String columnName,
      final int queryTimeout,
      final int queryLimit) {

    try {
      final DataFactory dataFactory = context.getRuntime().getDataFactory();
      final TableModel tableModel =
          dataFactory.queryData(
              query, new QueryDataRowWrapper(context.getDataRow(), queryLimit, queryTimeout));
      if (tableModel == null) {
        return null;
      }
      final int columnCount = tableModel.getColumnCount();
      if (tableModel.getRowCount() == 0 || columnCount == 0) {
        return null;
      }

      for (int column = 0; column < columnCount; column++) {
        if (columnName == null || columnName.equals(tableModel.getColumnName(column))) {
          final ArrayList<Object> values = new ArrayList<Object>();
          final int rowCount = tableModel.getRowCount();
          for (int row = 0; row < rowCount; row++) {
            values.add(tableModel.getValueAt(row, column));
          }
          return values.toArray();
        }
      }
    } catch (Exception e) {
      logger.warn("SingleValueQueryFunction: Failed to perform query", e);
    }
    return null;
  }
コード例 #2
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);
  }
コード例 #3
0
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    final ReportFieldNode that = (ReportFieldNode) o;

    if (fieldClass != null ? !fieldClass.equals(that.fieldClass) : that.fieldClass != null) {
      return false;
    }
    if (!fieldName.equals(that.fieldName)) {
      return false;
    }

    if (source != null ? !source.equals(that.source) : that.source != null) {
      return false;
    }

    return true;
  }
コード例 #4
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();
    }
  }
コード例 #5
0
 public int hashCode() {
   int result = source != null ? source.hashCode() : 0;
   result = 31 * result + fieldName.hashCode();
   result = 31 * result + (fieldClass != null ? fieldClass.hashCode() : 0);
   return result;
 }