public void transitionTo(final ScanningState state, final Transition transition) {
    if (statusBar.isDisposed() || transition == Transition.INIT) return;

    // TODO: separate GUI and non-GUI stuff
    switch (state) {
      case IDLE:
        // reset state text
        button.setEnabled(true);
        updateProgress(null, 0, 0);
        statusBar.setStatusText(null);
        break;
      case STARTING:
        // start the scan from scratch!
        resultTable.removeAll();
        try {
          scannerThread =
              scannerThreadFactory.createScannerThread(
                  feederRegistry.createFeeder(),
                  StartStopScanningAction.this,
                  createResultsCallback(state));
          stateMachine.startScanning();
          mainWindowTitle = statusBar.getShell().getText();
        } catch (RuntimeException e) {
          stateMachine.reset();
          throw e;
        }
        break;
      case RESTARTING:
        // restart the scanning - rescan
        resultTable.resetSelection();
        try {
          scannerThread =
              scannerThreadFactory.createScannerThread(
                  feederRegistry.createRescanFeeder(resultTable.getSelection()),
                  StartStopScanningAction.this,
                  createResultsCallback(state));
          stateMachine.startScanning();
          mainWindowTitle = statusBar.getShell().getText();
        } catch (RuntimeException e) {
          stateMachine.reset();
          throw e;
        }
        break;
      case SCANNING:
        scannerThread.start();
        break;
      case STOPPING:
        statusBar.setStatusText(Labels.getLabel("state.waitForThreads"));
        break;
      case KILLING:
        button.setEnabled(false);
        statusBar.setStatusText(Labels.getLabel("state.killingThreads"));
        break;
    }
    // change button image
    button.setImage(buttonImages[state.ordinal()]);
    button.setText(buttonTexts[state.ordinal()]);
  }
Exemplo n.º 2
0
  /** This method initializes main controls of the main window */
  private void initControlsArea(
      final Composite controlsArea,
      final Combo feederSelectionCombo,
      final Button startStopButton,
      final StartStopScanningAction startStopScanningAction,
      final ToolsActions.Preferences preferencesListener,
      final ToolsActions.ChooseFetchers chooseFetchersListsner) {
    controlsArea.setLayoutData(
        LayoutHelper.formData(
            new FormAttachment(feederArea),
            new FormAttachment(100),
            new FormAttachment(0),
            new FormAttachment(feederArea, 0, SWT.BOTTOM)));
    controlsArea.setLayout(LayoutHelper.formLayout(7, 3, 3));

    // steal the height from the second child of the FeederGUI - this must be the first edit box.
    // this results in better visual alignment with FeederGUIs
    Control secondControl = feederRegistry.current().getChildren()[1];
    // initialize global standard button height
    buttonHeight = secondControl.getSize().y + 2;

    // feeder selection combobox
    this.feederSelectionCombo = feederSelectionCombo;
    feederSelectionCombo.pack();
    IPFeederSelectionListener feederSelectionListener = new IPFeederSelectionListener();
    feederSelectionCombo.addSelectionListener(feederSelectionListener);
    // initialize the selected feeder GUI
    feederSelectionCombo.select(guiConfig.activeFeeder);
    feederSelectionCombo.setToolTipText(Labels.getLabel("combobox.feeder.tooltip"));

    // start/stop button
    this.startStopButton = startStopButton;
    shell.setDefaultButton(startStopButton);
    startStopButton.addSelectionListener(startStopScanningAction);

    // traverse the button before the combo (and don't traverse other buttons at all)
    controlsArea.setTabList(new Control[] {startStopButton, feederSelectionCombo});

    prefsButton = new ToolBar(controlsArea, SWT.FLAT);
    prefsButton.setCursor(prefsButton.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    ToolItem item = new ToolItem(prefsButton, SWT.PUSH);
    item.setImage(new Image(null, Labels.getInstance().getImageAsStream("button.preferences.img")));
    item.setToolTipText(Labels.getLabel("title.preferences"));
    item.addListener(SWT.Selection, preferencesListener);

    fetchersButton = new ToolBar(controlsArea, SWT.FLAT);
    fetchersButton.setCursor(fetchersButton.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    item = new ToolItem(fetchersButton, SWT.PUSH);
    item.setImage(new Image(null, Labels.getInstance().getImageAsStream("button.fetchers.img")));
    item.setToolTipText(Labels.getLabel("title.fetchers.select"));
    item.addListener(SWT.Selection, chooseFetchersListsner);

    feederSelectionListener.widgetSelected(null);
  }
Exemplo n.º 3
0
  private void relayoutControls() {
    boolean twoRowToolbar = Math.abs(feederRegistry.current().getSize().y - buttonHeight * 2) <= 10;

    feederSelectionCombo.setLayoutData(
        LayoutHelper.formData(
            SWT.DEFAULT, buttonHeight, new FormAttachment(0), null, new FormAttachment(0), null));
    if (twoRowToolbar) {
      startStopButton.setLayoutData(
          LayoutHelper.formData(
              feederSelectionCombo.getSize().x,
              Platform.MAC_OS ? SWT.DEFAULT : buttonHeight,
              new FormAttachment(0),
              null,
              new FormAttachment(feederSelectionCombo, 0),
              null));
      prefsButton.setLayoutData(
          LayoutHelper.formData(
              new FormAttachment(feederSelectionCombo),
              null,
              new FormAttachment(feederSelectionCombo, 0, SWT.CENTER),
              null));
      fetchersButton.setLayoutData(
          LayoutHelper.formData(
              new FormAttachment(startStopButton),
              null,
              new FormAttachment(startStopButton, 0, SWT.CENTER),
              null));
    } else {
      startStopButton.setLayoutData(
          LayoutHelper.formData(
              feederSelectionCombo.getSize().x,
              Platform.MAC_OS ? SWT.DEFAULT : buttonHeight,
              new FormAttachment(feederSelectionCombo),
              null,
              new FormAttachment(-1),
              null));
      prefsButton.setLayoutData(
          LayoutHelper.formData(
              new FormAttachment(startStopButton),
              null,
              new FormAttachment(feederSelectionCombo, 0, SWT.CENTER),
              null));
      fetchersButton.setLayoutData(
          LayoutHelper.formData(
              new FormAttachment(prefsButton),
              null,
              new FormAttachment(startStopButton, 0, SWT.CENTER),
              null));
    }
  }