示例#1
0
 @Override
 public boolean close() {
   recordingSupport.setMode(RecordingMode.Stopped);
   if (isDirty()) {
     if (!openSaveDialog()) {
       return false;
     }
   }
   final boolean result = super.close();
   if (result && !parentShell.isDisposed()) {
     dbc.dispose();
     parentShell.removeShellListener(closeListener);
     parentShell.setMinimized(false);
     try {
       ShellUtilsProvider.getShellUtils().forceActive(parentShell);
     } catch (CoreException e) {
       throw new RuntimeException(e);
     }
     parentShell.setFocus();
     ITestCase model = getModel();
     if (model != null && model.exists()) {
       IFile location = (IFile) model.getResource();
       if (location != null) {
         try {
           IDE.openEditor(Q7UIPlugin.getActiveWindow().getActivePage(), location);
         } catch (PartInitException e) {
           Q7UIPlugin.log(e);
         }
       }
     }
   }
   RecordingContextManager.Instance.deactivateContext();
   return result;
 }
示例#2
0
  private void updateRecognizeText(final Combo assertKind) {
    if (assertKind.getSelectionIndex() == TYPE_IMAGE_TEXT_CONTAINS) {
      AutLaunch launch = assertPanelWindow.getAut();
      Recognize recognize = TeslaFactory.eINSTANCE.createRecognize();
      // Extract image part
      Rectangle selection = getSelection();
      recognize.setX(selection.x);
      recognize.setY(selection.y);
      recognize.setWidth(selection.width);
      recognize.setHeight(selection.height);
      recognize.setImage(image);

      try {
        Object object = launch.execute(recognize);
        if (object instanceof RecognizeResponse) {
          RecognizeResponse resp = (RecognizeResponse) object;
          if (resp != null) {
            if (resp.getText() != null) {
              text.setText(resp.getText());
            } else {
              text.setText(""); // $NON-NLS-1$
            }
          }
        }
      } catch (Throwable e) {
        Q7UIPlugin.log(e);
      }
    }
  }
示例#3
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);
    }
  }
示例#4
0
 @Override
 protected IDialogSettings getDialogBoundsSettings() {
   final IDialogSettings root = Q7UIPlugin.getDefault().getDialogSettings();
   IDialogSettings section = root.getSection(SETTINGS_KEY);
   if (section == null) {
     section = root.addNewSection(SETTINGS_KEY);
   }
   return section;
 }
示例#5
0
 public void handleChange(ChangeEvent event) {
   Q7UIPlugin.getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               updateStatusBar();
               updateAssetionWindow();
             }
           });
 }
示例#6
0
 private static String getTitle(ExecutionStatus status) {
   IQ7NamedElement element = status.getElement();
   if (element != null) {
     if (element instanceof IContext) {
       try {
         return NLS.bind(
             Messages.ControlPanelWindow_ExecutionFailedDialogTitle_Context,
             element.getElementName());
       } catch (ModelException e) {
         Q7UIPlugin.log(e);
       }
     }
   }
   return Messages.ControlPanelWindow_ExecutionFailedDialogTitle_Script;
 }
示例#7
0
 public void assertAdded(final CommandSet commands) {
   Q7UIPlugin.getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               if (commands != null) {
                 if (assertionWindow == null
                     || assertionWindow.getShell() == null
                     || assertionWindow.getShell().isDisposed()) {
                   assertionWindow = new AssertionPanelWindow(recordingSupport, getShell());
                 }
                 assertionWindow.setInput(commands);
               }
             }
           });
 }
示例#8
0
  public boolean matches(IQ7NamedElement object, String query, SubMonitor monitor) {
    if (!(object instanceof ITestCase)) {
      return false;
    }

    final ITestCase scenario = (ITestCase) object;
    try {
      if (scenario.getExternalReference() != null
          && scenario.getExternalReference().toLowerCase().contains(query)) {
        return true;
      }
    } catch (ModelException e) {
      Q7UIPlugin.log(e);
    }

    return false;
  }
示例#9
0
  public void run() {

    TextViewer viewer = getTextViewer();
    if (viewer == null) return;

    IDocument document = viewer.getDocument();
    if (document == null) return;

    try {
      fLastLine = document.getLineOfOffset(document.getLength()) + 1;
    } catch (BadLocationException ex) {
      IStatus status =
          new Status(
              IStatus.ERROR,
              Q7UIPlugin.PLUGIN_ID,
              IStatus.OK,
              "Go to Line failed",
              ex); //$NON-NLS-1$
      Q7UIPlugin.getDefault().getLog().log(status);
      return;
    }

    String title = DIALOG_TITLE;
    String message = MessageFormat.format(DIALOG_MESSAGE, new Integer(fLastLine));

    String currentLineStr = ""; // $NON-NLS-1$
    StyledText textWidget = viewer.getTextWidget();
    int currentLine = textWidget.getLineAtOffset(textWidget.getCaretOffset());
    if (currentLine > -1) currentLineStr = Integer.toString(currentLine + 1);

    InputDialog d =
        new InputDialog(
            viewer.getTextWidget().getShell(),
            title,
            message,
            currentLineStr,
            new NumberValidator());
    if (d.open() == Window.OK) {
      try {
        int line = Integer.parseInt(d.getValue());
        gotoLine(line - 1);
      } catch (NumberFormatException x) {
      }
    }
  }
示例#10
0
  private boolean isDirty() {
    ITestCase model = getModel();
    if (model != null && model.exists()) {
      try {
        Scenario saved = (Scenario) model.getNamedElement();
        if (saved != null) {
          if (!EcoreUtil.equals(saved.getContent(), scenario.getContent())) return true;

          // special case when underlying Script model object is still
          // not created
          if (saved.getContent() == null) {
            if (!EcoreUtil.equals(saved.getTeslaContent(), scenario.getTeslaContent())) return true;
          }

          if (saved.getContexts().size() != scenario.getContexts().size()) return true;
          int size = saved.getContexts().size();
          for (int i = 0; i < size; i++) {
            if (!saved.getContexts().get(i).equals(scenario.getContexts().get(i))) return true;
          }

          if (saved.getVerifications().size() != scenario.getVerifications().size()) return true;
          size = saved.getVerifications().size();
          for (int i = 0; i < size; i++) {
            if (!saved.getVerifications().get(i).equals(scenario.getVerifications().get(i)))
              return true;
          }

          String savedDesc = saved.getDescription();
          String desc = scenario.getDescription();
          if (savedDesc == null && desc != null) return true;
          if (savedDesc != null && !savedDesc.equals(desc)) return true;
          return false;
        }
        return model.hasUnsavedChanges();
      } catch (ModelException e) {
        Q7UIPlugin.log(e);
      }
    }
    String content = Scenarios.getScriptContent(scenario);
    return content != null && content.length() > 0;
  }
示例#11
0
 private boolean hasDialogBoundsSettings() {
   final IDialogSettings root = Q7UIPlugin.getDefault().getDialogSettings();
   return root.getSection(SETTINGS_KEY) != null;
 }
示例#12
0
  private void createToolBar(Composite parent) {
    final Composite toolbarComposite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(1).applyTo(toolbarComposite);
    toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    CoolBarManager coolBarManager = new CoolBarManager(SWT.HORIZONTAL | SWT.FLAT);
    {
      ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
      IAction homeAction =
          new Action() {
            @Override
            public void run() {
              close();
            }
          };
      homeAction.setToolTipText(Messages.ControlPanelWindow_ReturnActionTooltip);
      homeAction.setImageDescriptor(Images.getImageDescriptor(Images.PANEL_HOME));
      manager.add(homeAction);

      IAction saveAction =
          new Action() {
            @Override
            public void run() {
              if (getModel() != null) {
                save();
              } else {
                saveAs();
              }
            }
          };

      saveAction.setMenuCreator(
          new ActionMenuCreator() {
            @Override
            protected void fill(MenuManager manager) {
              manager.add(
                  new Action(Messages.ControlPanelWindow_SaveAction) {
                    {
                      dbc.bindValue(
                          Actions.observeEnabled(this),
                          new ComputedValue() {
                            @Override
                            protected Object calculate() {
                              return getModel() != null;
                            }
                          });
                    }

                    @Override
                    public void run() {
                      save();
                    }
                  });
              manager.add(
                  new Action(Messages.ControlPanelWindow_SaveAsAction) {
                    @Override
                    public void run() {
                      saveAs();
                    }
                  });
            }
          });
      dbc.bindValue(
          Actions.observeToolTipText(saveAction),
          new ComputedValue() {
            @Override
            protected Object calculate() {
              if (getModel() != null) {
                return Messages.ControlPanelWindow_SaveAction;
              } else {
                return Messages.ControlPanelWindow_SaveAsAction;
              }
            }
          });
      ISharedImages sharedImages = WorkbenchPlugin.getDefault().getSharedImages();
      saveAction.setImageDescriptor(
          sharedImages.getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT));
      saveAction.setDisabledImageDescriptor(
          sharedImages.getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT_DISABLED));
      manager.add(saveAction);
      coolBarManager.add(manager);
    }
    {
      ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
      manager.add(createRecordAction());
      manager.add(createReplayAction());
      coolBarManager.add(manager);
    }
    {
      ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL | SWT.FLAT);
      manager.add(createRecordingModeAction());
      manager.add(createAssertingModeAction());
      if (Q7UIPlugin.isImageRecognitionAllowed()) {
        manager.add(createImageRecognitionModeAction());
      }
      coolBarManager.add(manager);
    }
    coolBar = coolBarManager.createControl(toolbarComposite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(coolBar);
    coolBar.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            getShell().layout();
          }
        });
  }
示例#13
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;
  }