Esempio n. 1
0
  /** @param parent a widget which will be the parent of the new instance (cannot be null) */
  public RDataTableComposite(final Composite parent, final IRDataTableCallbacks callbacks) {
    super(parent, SWT.NONE);

    if (callbacks == null) {
      throw new NullPointerException("callbacks"); // $NON-NLS-1$
    }

    this.display = getDisplay();
    this.callbacks = callbacks;

    this.layout = new StackLayout();
    setLayout(this.layout);

    this.messageControl = new Label(this, SWT.NONE);
    showDummy("Preparing...");
  }
Esempio n. 2
0
  public void setInput(final IRDataTableInput input) {
    if (this.tableLayers != null) {
      showDummy(""); // $NON-NLS-1$
      this.tableLayers.table.dispose();
      this.tableLayers.table = null;
      this.dataProvider = null;
      this.setAnchorByData = null;
    }
    if (input != null) {
      showDummy("Preparing (" + input.getName() + ")...");
      try {
        final IToolRunnable runnable =
            new ISystemRunnable() {

              @Override
              public String getTypeId() {
                return "r/dataeditor/init"; //$NON-NLS-1$
              }

              @Override
              public String getLabel() {
                return "Prepare Data Viewer (" + input.getName() + ")";
              }

              @Override
              public boolean isRunnableIn(final ITool tool) {
                return true; // TODO
              }

              @Override
              public boolean changed(final int event, final ITool process) {
                if (event == MOVING_FROM) {
                  return false;
                }
                return true;
              }

              @Override
              public void run(final IToolService service, final IProgressMonitor monitor)
                  throws CoreException {
                final IRToolService r = (IRToolService) service;

                final AtomicReference<AbstractRDataProvider<?>> dataProvider =
                    new AtomicReference<>();
                Exception error = null;
                try {
                  final RObject struct =
                      r.evalData(
                          input.getFullName(), null, RObjectFactory.F_ONLY_STRUCT, 1, monitor);
                  RCharacterStore classNames = null;
                  {
                    final FunctionCall call = r.createFunctionCall("class"); // $NON-NLS-1$
                    call.add(input.getFullName());
                    classNames = RDataUtil.checkRCharVector(call.evalData(monitor)).getData();
                  }

                  switch (struct.getRObjectType()) {
                    case RObject.TYPE_VECTOR:
                      dataProvider.set(new RVectorDataProvider(input, (RVector<?>) struct));
                      break;
                    case RObject.TYPE_ARRAY:
                      {
                        final RArray<?> array = (RArray<?>) struct;
                        if (array.getDim().getLength() == 2) {
                          if (classNames.contains("ftable")) { // $NON-NLS-1$
                            dataProvider.set(new FTableDataProvider(input, array));
                            break;
                          }
                          dataProvider.set(new RMatrixDataProvider(input, array));
                          break;
                        }
                        break;
                      }
                    case RObject.TYPE_DATAFRAME:
                      dataProvider.set(new RDataFrameDataProvider(input, (RDataFrame) struct));
                      break;
                    default:
                      break;
                  }
                } catch (final CoreException e) {
                  error = e;
                } catch (final UnexpectedRDataException e) {
                  error = e;
                }
                final IStatus status;
                if (error != null) {
                  status =
                      new Status(
                          IStatus.ERROR,
                          RUI.PLUGIN_ID,
                          "An error occurred when preparing the R data viewer.",
                          error);
                  StatusManager.getManager().handle(status);
                } else if (dataProvider.get() == null) {
                  status =
                      new Status(
                          IStatus.INFO,
                          RUI.PLUGIN_ID,
                          "This R element type is not supported.",
                          null);
                } else {
                  status = null;
                }
                RDataTableComposite.this.display.asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        RDataTableComposite.this.dataProvider = null;
                        if (!UIAccess.isOkToUse(RDataTableComposite.this)) {
                          return;
                        }
                        if (status == null) {
                          initTable(input, dataProvider.get());
                        } else {
                          showDummy(status.getMessage());
                        }
                      }
                    });
              }
            };
        final IStatus status = input.getTool().getQueue().add(runnable);
        if (status.getSeverity() >= IStatus.ERROR) {
          throw new CoreException(status);
        }
      } catch (final CoreException e) {
        showDummy(e.getLocalizedMessage());
      }
    }
  }