Exemplo n.º 1
0
  private void save() {
    try {
      ITestCase model = getModel();
      NullProgressMonitor monitor = new NullProgressMonitor();
      if (model.exists()) {
        model = (ITestCase) model.getWorkingCopy(monitor);
        copyContent(scenario, (Scenario) model.getNamedElement());
        WriteAccessChecker writeAccessChecker = new WriteAccessChecker(getShell());

        try {
          if (!writeAccessChecker.makeResourceWritable(model)) {
            return;
          }
          model.commitWorkingCopy(true, monitor);
        } catch (CoreException e) {
          Q7UIPlugin.log(e);
        } finally {
          model.discardWorkingCopy();
        }
        contextsTable.setProject(getSavedProject());
        verificationsTable.setProject(getSavedProject());
        copyContent((Scenario) model.getNamedElement(), this.scenario);
      } else {
        MessageDialog dialog =
            new MessageDialog(
                getShell(),
                Messages.ControlPanelWindow_SaveDialogTitle,
                null,
                "Failed to save testcase because underlying resources is not exist.",
                MessageDialog.ERROR,
                new String[] {
                  IDialogConstants.YES_LABEL,
                  IDialogConstants.NO_LABEL,
                  IDialogConstants.CANCEL_LABEL
                },
                0);
        int value = dialog.open(); // Number of pressed button
        if (value == 0) {
          saveAs();
        }
      }
    } catch (ModelException e) {
      Q7UIPlugin.log(e);
    }
  }
Exemplo n.º 2
0
  @Override
  protected Control createContents(Composite parent) {
    Q7UIPlugin.getDisplay().addFilter(SWT.KeyUp, keyListener);

    createToolBar(parent);
    createTabFolder(parent);

    ITestCase model = getModel();
    Q7InternalTestCase internalModel =
        new Q7InternalTestCase(
            ModelManager.getModelManager().getModel(), "recording_snippet", scenario);

    scriptPart =
        new ScriptComposite(
            internalModel,
            model != null ? (IFile) getModel().getResource() : null,
            getShell(),
            SWT.SCROLL_LOCK);
    ComputedValue recordingMode =
        new ComputedValue() {
          @Override
          protected Object calculate() {
            return recordingSupport.getMode();
          }
        };
    dbc.bindValue(scriptPart.observeRecordingMode(), recordingMode);
    script = tabFolder.addTab(scriptPart);
    try {
      contextsTable = new ContextsTable(internalModel);
    } catch (ModelException e) {
      Q7UIPlugin.log(e);
    }
    contextsTable.setProject(getSavedProject());
    dbc.bindValue(contextsTable.observeRecordingMode(), recordingMode);
    tabFolder.addTab(contextsTable);

    try {
      verificationsTable = new VerificationsTable(internalModel);
    } catch (ModelException e) {
      Q7UIPlugin.log(e);
    }
    verificationsTable.setProject(getSavedProject());
    dbc.bindValue(verificationsTable.observeRecordingMode(), recordingMode);
    tabFolder.addTab(verificationsTable);

    DescriptionComposite descPart = new DescriptionComposite(scenario);
    dbc.bindValue(descPart.observeRecordingMode(), recordingMode);
    tabFolder.addTab(descPart);
    OptionsComposite optionsComposite = new OptionsComposite();
    tabFolder.addTab(optionsComposite);
    optionsComposite.setOptionChangeCallback(
        new Runnable() {
          public void run() {
            if (recordingSupport.getMode() == RecordingMode.Recording) {
              recordingSupport.sendFeatures();
            }
          }
        });

    selectTab(script);

    statusBar =
        new StatusBarComposite() {
          @Override
          protected void layout() {
            super.layout();
            tabFolder.layout(true);
          }

          @Override
          protected void handleError(final String taskMessage, Throwable e) {
            if (e instanceof CoreException
                && (e.getMessage().equals("Connection reset")
                    || e //$NON-NLS-1$
                        .getMessage()
                        .equals("Connection refused: connect"))) { // $NON-NLS-1$
              return; // Ignore connection lost exception, this situation
              // handled in RecordingSupport class
            }
            if (e instanceof CoreException) {
              final IStatus status = ((CoreException) e).getStatus();
              if (status instanceof ExecutionStatus && PlatformUI.isWorkbenchRunning()) {
                WorkbenchUtils.uiRun(
                    new Runnable() {
                      public void run() {
                        displayExecutionFailure((ExecutionStatus) status);
                      }
                    });
                return;
              }
            }
            super.handleError(taskMessage, e);
          };
        };
    statusBar.createControl(parent);
    // statusBar.getControl().addKeyListener(keyListener);
    dbc.bindValue(
        WidgetProperties.text().observe(getShell()),
        new ComputedValue() {
          @Override
          protected Object calculate() {
            StringBuilder text = new StringBuilder(Messages.ControlPanelWindow_Title);
            ITestCase model = getModel();
            if (model != null && model.exists()) {
              try {
                text.append(" - ").append(model.getElementName()); // $NON-NLS-1$
                text.append(" (") // $NON-NLS-1$
                    .append(model.getQ7Project().getName())
                    .append(")"); // $NON-NLS-1$
              } catch (ModelException e) {
                Q7UIPlugin.log(e);
              }
            }
            AutLaunch aut = recordingSupport.getAUT();
            if (aut != null) {
              text.append(" - ").append(aut.getAut().getName()); // $NON-NLS-1$
            }
            switch (recordingSupport.getMode()) {
              case Connecting:
                text.append(Messages.ControlPanelWindow_StatusConnection);
                break;
              case Recording:
                text.append(Messages.ControlPanelWindow_StatusRecording);
                break;
              case Asserting:
                text.append(Messages.ControlPanelWindow_StatusAsserting);
                break;
              case ImageRecognition:
                text.append(Messages.ControlPanelWindow_StatusImageRecognition);
                break;
              case Replaying:
                text.append(Messages.ControlPanelWindow_StatusReplaying);
                break;
              case WaitingForAUTRestart:
                text.append(Messages.ControlPanelWindow_StatusWaitingAUTToRestart);
                break;
              default:
                break;
            }
            return text.toString();
          }
        });

    tabFolder.setFocus();

    return tabFolder;
  }