Ejemplo n.º 1
0
 protected int getColumnFormatterCharWidth(final int columnPosition) {
   if (fDataProvider.getAllColumnsEqual()) {
     final RDataTableContentDescription formatter = fDataProvider.getDescription();
     if (formatter != null
         && formatter.defaultDataFormatter != null
         && formatter.defaultDataFormatter.getAutoWidth() >= 0) {
       return formatter.defaultDataFormatter.getAutoWidth();
     }
     return fColumnFallbackWidth;
   } else {
     final RDataTableContentDescription description = fDataProvider.getDescription();
     if (description != null) {
       if (columnPosition < description.dataColumns.length
           && description.dataColumns[columnPosition] != null
           && description.dataColumns[columnPosition].getDefaultFormat().getAutoWidth() >= 0) {
         return description.dataColumns[columnPosition].getDefaultFormat().getAutoWidth();
       }
       if (description.defaultDataFormatter != null
           && description.defaultDataFormatter.getAutoWidth() >= 0) {
         return description.defaultDataFormatter.getAutoWidth();
       }
     }
     return fColumnFallbackWidth;
   }
 }
Ejemplo n.º 2
0
  private int aggregateWidth(final int position) {
    if (position < 0) {
      return -1;
    }

    if (fDataProvider.getAllColumnsEqual()) {
      final Integer columnWidth = fCustomColumnWidths.get(Integer.valueOf(0));
      if (columnWidth != null) {
        return columnWidth * position;
      } else {
        return getColumnDefaultWidth(0) * position;
      }
    }

    int width = 0;
    for (int i = 0; i < position; i++) {
      final Integer columnWidth = fCustomColumnWidths.get(Integer.valueOf(i));
      if (columnWidth != null) {
        width += columnWidth.intValue();
      } else {
        width += getColumnDefaultWidth(i);
      }
    }
    return width;
  }
Ejemplo n.º 3
0
 public int getColumnWidthByPosition(final int columnPosition) {
   final Integer columnWidth =
       fCustomColumnWidths.get(
           fDataProvider.getAllColumnsEqual()
               ? Integer.valueOf(0)
               : Integer.valueOf(columnPosition));
   if (columnWidth != null) {
     return columnWidth.intValue();
   }
   return getColumnDefaultWidth(columnPosition);
 }
Ejemplo n.º 4
0
  protected void initTable(
      final IRDataTableInput input, final AbstractRDataProvider<? extends RObject> dataProvider) {
    this.input = input;
    this.dataProvider = dataProvider;

    final PresentationConfig presentation = PresentationConfig.getInstance(this.display);

    final TableLayers layers = new TableLayers();

    layers.dataLayer = new RDataLayer(dataProvider, presentation.getBaseSizeConfig());

    if (!this.dataProvider.getAllColumnsEqual()) {
      //			final ColumnOverrideLabelAccumulator columnLabelAccumulator =
      //					new ColumnOverrideLabelAccumulator(dataLayer);
      //			for (long i= 0; i < fDataProvider.getColumnCount(); i++) {
      //				columnLabelAccumulator.registerColumnOverrides(i,
      // ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + i);
      //			}
      final AggregrateConfigLabelAccumulator aggregateLabelAccumulator =
          new AggregrateConfigLabelAccumulator();
      //			aggregateLabelAccumulator.add(columnLabelAccumulator);
      //			dataLayer.setConfigLabelAccumulator(aggregateLabelAccumulator);
    }

    //		final WColumnReorderLayer columnReorderLayer= new WColumnReorderLayer(dataLayer);
    //		final ColumnHideShowLayer columnHideShowLayer= new ColumnHideShowLayer(columnReorderLayer);

    layers.selectionLayer = new SelectionLayer(layers.dataLayer, false);
    layers.selectionLayer.addConfiguration(new UIBindings.SelectionConfiguration());
    layers.selectionLayer.addConfiguration(new DefaultTickUpdateConfiguration());

    layers.viewportLayer = new ViewportLayer(layers.selectionLayer);

    {
      final FreezeLayer freezeLayer = new FreezeLayer(layers.selectionLayer);
      final CompositeFreezeLayer compositeFreezeLayer =
          new CompositeFreezeLayer(freezeLayer, layers.viewportLayer, layers.selectionLayer, true);
      layers.topBodyLayer = compositeFreezeLayer;
    }

    {
      final IDataProvider headerDataProvider = dataProvider.getColumnDataProvider();
      layers.dataColumnHeaderLayer =
          (headerDataProvider instanceof ISpanningDataProvider)
              ? new SpanningDataLayer(
                  (ISpanningDataProvider) headerDataProvider,
                  PositionId.BODY_CAT,
                  10,
                  PositionId.HEADER_CAT,
                  10)
              : new DataLayer(
                  headerDataProvider, PositionId.BODY_CAT, 10, PositionId.HEADER_CAT, 10);

      final ColumnHeaderLayer layer =
          new ColumnHeaderLayer(
              layers.dataColumnHeaderLayer,
              layers.topBodyLayer,
              layers.selectionLayer,
              false,
              presentation.getHeaderLayerPainter());
      layer.addConfiguration(new UIBindings.ColumnHeaderConfiguration());
      layers.topColumnHeaderLayer = layer;
    }
    final ISortModel sortModel = dataProvider.getSortModel();
    if (sortModel != null) {
      final SortHeaderLayer<?> sortHeaderLayer =
          new SortHeaderLayer<>(layers.topColumnHeaderLayer, sortModel, false);
      sortHeaderLayer.addConfiguration(new UIBindings.SortConfiguration());
      layers.topColumnHeaderLayer = sortHeaderLayer;
    }
    {
      final IDataProvider headerDataProvider = dataProvider.getRowDataProvider();
      layers.dataRowHeaderLayer =
          (headerDataProvider instanceof ISpanningDataProvider)
              ? new SpanningDataLayer(
                  (ISpanningDataProvider) headerDataProvider,
                  PositionId.HEADER_CAT,
                  10,
                  PositionId.BODY_CAT,
                  10)
              : new DataLayer(
                  headerDataProvider, PositionId.HEADER_CAT, 10, PositionId.BODY_CAT, 10);

      layers.topRowHeaderLayer =
          new RowHeaderLayer(
              layers.dataRowHeaderLayer,
              layers.topBodyLayer,
              layers.selectionLayer,
              false,
              presentation.getHeaderLayerPainter());
    }
    final IDataProvider cornerDataProvider =
        new DefaultCornerDataProvider(
            layers.dataColumnHeaderLayer.getDataProvider(),
            layers.dataRowHeaderLayer.getDataProvider());

    final GridLayer gridLayer;
    if (dataProvider.getColumnLabelProvider() != null
        || dataProvider.getRowLabelProvider() != null) {
      layers.topColumnHeaderLayer = new ExtColumnHeaderLayer(layers.topColumnHeaderLayer);
      layers.topRowHeaderLayer = new ExtRowHeaderLayer(layers.topRowHeaderLayer);
      final CornerLayer cornerLayer =
          new LabelCornerLayer(
              new DataLayer(
                  cornerDataProvider, PositionId.HEADER_CAT, 10, PositionId.HEADER_CAT, 10),
              layers.topRowHeaderLayer,
              layers.topColumnHeaderLayer,
              dataProvider.getColumnLabelProvider(),
              dataProvider.getRowLabelProvider(),
              false,
              presentation.getHeaderLabelLayerPainter());
      gridLayer =
          new ExtGridLayer(
              layers.topBodyLayer,
              layers.topColumnHeaderLayer,
              layers.topRowHeaderLayer,
              cornerLayer,
              false);
    } else {
      final CornerLayer cornerLayer =
          new CornerLayer(
              new DataLayer(cornerDataProvider, PositionId.HEADER_CAT),
              layers.topRowHeaderLayer,
              layers.topColumnHeaderLayer,
              false,
              presentation.getHeaderLayerPainter());
      gridLayer =
          new GridLayer(
              layers.topBodyLayer,
              layers.topColumnHeaderLayer,
              layers.topRowHeaderLayer,
              cornerLayer,
              false);
    }
    gridLayer.addConfigLabelAccumulatorForRegion(
        GridRegion.BODY, new AlternatingRowConfigLabelAccumulator());

    final Runnable configRunnable =
        new Runnable() {
          @Override
          public void run() {
            final TableLayers layers = RDataTableComposite.this.tableLayers;
            if (layers == null) {
              return;
            }

            final LayoutSizeConfig sizeConfig = presentation.getBaseSizeConfig();

            layers.dataLayer.setSizeConfig(sizeConfig);
            layers.dataColumnHeaderLayer.setDefaultRowHeight(sizeConfig.getRowHeight());
            layers.dataRowHeaderLayer.setDefaultColumnWidth(
                sizeConfig.getCharWidth() * 8 + sizeConfig.getDefaultSpace() * 2);
            if (layers.topColumnHeaderLayer instanceof ExtColumnHeaderLayer) {
              ((ExtColumnHeaderLayer) layers.topColumnHeaderLayer)
                  .setSpaceSize(sizeConfig.getRowHeight());
              ((ExtRowHeaderLayer) layers.topRowHeaderLayer)
                  .setSpaceSize(sizeConfig.getRowHeight());
            }

            presentation.configureRegistry(layers.table.getConfigRegistry());

            layers.table.updateResize();
          }
        };
    presentation.addListener(configRunnable);

    final ITableUIContext uiContext = new RUIContext();
    //		{	final ILayerCommandHandler<?> commandHandler= new
    // ScrollCommandHandler(fTableLayers.viewportLayer);
    //			fTableLayers.viewportLayer.registerCommandHandler(commandHandler);
    //		}
    {
      final ILayerCommandHandler<?> commandHandler =
          new SelectRelativeCommandHandler(layers.selectionLayer);
      layers.viewportLayer.registerCommandHandler(commandHandler);
      layers.selectionLayer.registerCommandHandler(commandHandler);
    }
    {
      final ILayerCommandHandler<?> commandHandler =
          new CopyToClipboardCommandHandler(layers.selectionLayer, uiContext);
      layers.selectionLayer.registerCommandHandler(commandHandler);
    }
    {
      final ILayerCommandHandler<?> commandHandler =
          new InitializeAutoResizeCommandHandler(layers.selectionLayer);
      gridLayer.registerCommandHandler(commandHandler);
    }
    if (sortModel != null) {
      final ILayerCommandHandler<?> commandHandler = new SortPositionCommandHandler(sortModel);
      layers.dataLayer.registerCommandHandler(commandHandler);
    }
    if (sortModel != null) {
      final ILayerCommandHandler<?> commandHandler = new ClearSortCommandHandler(sortModel);
      layers.dataLayer.registerCommandHandler(commandHandler);
    }

    layers.table = new NatTable(this, gridLayer, false);
    layers.table.addConfiguration(presentation);
    layers.table.addConfiguration(new UIBindings.HeaderContextMenuConfiguration(layers.table));
    layers.table.addConfiguration(
        new UIBindings.BodyContextMenuConfiguration(
            layers.table, this.callbacks.getServiceLocator()));

    layers.table.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(final DisposeEvent e) {
            dataProvider.dispose();
          }
        });

    final IConfigRegistry registry = layers.table.getConfigRegistry();
    registry.registerConfigAttribute(
        CellConfigAttributes.DISPLAY_CONVERTER, new RDataFormatterConverter(dataProvider));
    registry.registerConfigAttribute(
        CellConfigAttributes.DISPLAY_CONVERTER,
        new RDataFormatterConverter.RowHeader(dataProvider),
        DisplayMode.NORMAL,
        GridRegion.ROW_HEADER);

    this.tableLayers = layers;
    this.tableInitialized = false;

    configRunnable.run();

    this.tableLayers.table.addLayerListener(
        new ILayerListener() {
          @Override
          public void handleLayerEvent(final ILayerEvent event) {
            if (event instanceof ISelectionEvent) {
              scheduleUpdateSelection(false, 100);
              return;
            }
            if (event instanceof IVisualChangeEvent) {
              scheduleUpdateSelection(true, 100);
              return;
            }
          }
        });
    dataProvider.addDataChangedListener(
        new AbstractRDataProvider.IDataProviderListener() {
          @Override
          public void onInputInitialized(final boolean structChanged) {
            if (layers != RDataTableComposite.this.tableLayers || layers.table.isDisposed()) {
              return;
            }

            if (layers.table != RDataTableComposite.this.layout.topControl) {
              layers.table.configure();
            }

            if (layers.table != RDataTableComposite.this.layout.topControl) {
              RDataTableComposite.this.layout.topControl = layers.table;
              layout();
            }
            if (!RDataTableComposite.this.tableInitialized) {
              layers.selectionLayer.setSelectedCell(0, 0);
            } else if (structChanged) {
              layers.dataLayer.fireLayerEvent(new RowStructuralRefreshEvent(layers.dataLayer));
            } else {
              layers.dataLayer.fireLayerEvent(
                  new RowUpdateEvent(
                      layers.dataLayer, new LRange(0, layers.dataLayer.getRowCount())));
            }

            RDataTableComposite.this.selection = null;
            scheduleUpdateSelection(true, 0);

            for (final IRDataTableListener listener :
                RDataTableComposite.this.tableListeners.toArray()) {
              listener.inputChanged(input, dataProvider.getDescription());
            }
          }

          @Override
          public void onInputFailed(final int error) {
            if (error == ERROR_STRUCT_CHANGED) {
              showReload();
            } else {
              showDummy("An error occurred when loading the table input.");
              for (final IRDataTableListener listener :
                  RDataTableComposite.this.tableListeners.toArray()) {
                listener.inputChanged(null, null);
              }
            }
          }

          @Override
          public void onRowCountChanged() {
            final TableLayers layers = RDataTableComposite.this.tableLayers;
            if (layers == null || layers.table != layers.table || layers.table.isDisposed()) {
              return;
            }

            layers.dataLayer.fireLayerEvent(new RowStructuralRefreshEvent(layers.dataLayer));

            RDataTableComposite.this.selection = null;
            scheduleUpdateSelection(true, 0);
          }

          @Override
          public void onRowsChanged(final long beginIdx, final long endIdx) {
            RDataTableComposite.this.display.asyncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    final TableLayers layers = RDataTableComposite.this.tableLayers;
                    if (layers == null
                        || layers.table != layers.table
                        || layers.table.isDisposed()) {
                      return;
                    }
                    layers.dataLayer.fireLayerEvent(
                        new RowUpdateEvent(layers.dataLayer, new LRange(beginIdx, endIdx)));
                  }
                });
          }
        });
    dataProvider.addFindListener(this.findListener);
  }
Ejemplo n.º 5
0
 public int getPreferredColumnCount() {
   return fDataProvider.getColumnCount();
 }
Ejemplo n.º 6
0
 public Object getDataValueByPosition(final int columnPosition, final int rowPosition) {
   final int columnIndex = getColumnIndexByPosition(columnPosition);
   final int rowIndex = getRowIndexByPosition(rowPosition);
   return fDataProvider.getDataValue(columnIndex, rowIndex);
 }
Ejemplo n.º 7
0
 public int getRowCount() {
   return fDataProvider.getRowCount();
 }
Ejemplo n.º 8
0
 public void setColumnWidthToAutoWidth(final int columnPosition) {
   fCustomColumnWidths.put(
       fDataProvider.getAllColumnsEqual() ? Integer.valueOf(0) : Integer.valueOf(columnPosition),
       getColumnAutoWidth(columnPosition));
   fireLayerEvent(new ColumnResizeEvent(this, columnPosition));
 }