예제 #1
0
 /**
  * Create a new instance of <code>LockToolBarAction</code>
  *
  * @param window the workbench window this action applies to
  */
 public LockToolBarAction(IWorkbenchWindow window) {
   super(WorkbenchMessages.LockToolBarAction_text);
   if (window == null) {
     throw new IllegalArgumentException();
   }
   this.workbenchWindow = window;
   setActionDefinitionId("org.eclipse.ui.window.lockToolBar"); // $NON-NLS-1$
   // @issue missing action id
   setToolTipText(WorkbenchMessages.LockToolBarAction_toolTip);
   setEnabled(true);
   // queue the update for the checked state since this action is created
   // before the coolbar
   window
       .getWorkbench()
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               if (workbenchWindow instanceof WorkbenchWindow) {
                 setChecked(((WorkbenchWindow) workbenchWindow).isCoolBarLocked());
               }
             }
           });
   window
       .getWorkbench()
       .getHelpSystem()
       .setHelp(this, IWorkbenchHelpContextIds.LOCK_TOOLBAR_ACTION);
 }
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IWorkbenchPage page = window.getActivePage();
    View view = (View) page.findView(View.ID);
    view.getViewer().refresh();

    // open dialog to get path
    FileDialog filedlg = new FileDialog(window.getShell(), SWT.SAVE);
    filedlg.setText("Create Sequence Diagram File");
    filedlg.setFilterPath("SystemRoot");
    filedlg.setFilterExtensions(new String[] {"di"});
    String selected = filedlg.open();

    // create & initial the sequence diagram
    MyCreater myCreater = new MyCreater();
    myCreater.init(window.getWorkbench(), new StructuredSelection()); // fixed bug
    IFile iFile = myCreater.create(selected);

    // create the model
    SequenceDiagram sdDiagram = new SequenceDiagram();
    sdDiagram.setiFile(iFile);
    sdDiagram.setFilePath(
        new Path(selected).removeFileExtension().addFileExtension("uml").toOSString());
    ModelManager.getInstance().AddModel(sdDiagram);

    // open the editor
    myCreater.open(iFile);

    // refresh the model viewer
    view.getViewer().refresh();

    return null;
  }
 private void addResetItem(final Menu menu) {
   final MenuItem resetMenuItem = new MenuItem(menu, SWT.Activate);
   resetMenuItem.setText(WorkbenchMessages.PerspectiveBar_reset);
   final IWorkbenchWindow workbenchWindow = window.getContext().get(IWorkbenchWindow.class);
   workbenchWindow
       .getWorkbench()
       .getHelpSystem()
       .setHelp(resetMenuItem, IWorkbenchHelpContextIds.RESET_PERSPECTIVE_ACTION);
   resetMenuItem.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
           if (psTB.isDisposed()) return;
           IHandlerService handlerService =
               (IHandlerService) workbenchWindow.getService(IHandlerService.class);
           IStatus status = Status.OK_STATUS;
           try {
             handlerService.executeCommand(
                 IWorkbenchCommandConstants.WINDOW_RESET_PERSPECTIVE, null);
           } catch (ExecutionException e) {
             status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e.getMessage(), e);
           } catch (NotDefinedException e) {
             status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e.getMessage(), e);
           } catch (NotEnabledException e) {
             status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e.getMessage(), e);
           } catch (NotHandledException e) {
           }
           if (!status.isOK())
             StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
         }
       });
 }
  public void run() {
    NewPHPClassWizard wizard = new NewPHPClassWizard();
    wizard.init(window.getWorkbench(), getSelection());

    WizardDialog wizardDialog = new WizardDialog(window.getShell(), wizard);
    wizardDialog.open();
  }
예제 #5
0
  @Override
  public void run(IAction action) {

    try {
      IWorkbenchWindow windoow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      RefactoringWizard wizard = new RefactoringWizard();

      ITextSelection textSelection = getITextSelection();

      int startLine = textSelection.getStartLine() + 1;
      int endLine = textSelection.getEndLine() + 1;
      InOneMethodVisitor iomv = new InOneMethodVisitor(getICompilationUnit(), startLine, endLine);
      if (iomv.isInOne()) {
        wizard.init(windoow.getWorkbench(), getICompilationUnit(), getITextSelection());
        WizardDialog dialog = new WizardDialog(shell, wizard);
        dialog.open();
      } else {
        throw new Exception("Selected Code Block Illegal!");
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      alert(e);
      e.printStackTrace();
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
   * .ExecutionEvent)
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {

    LoadModelInstanceWizard wizard;
    WizardDialog dialog;

    ISelection currentSelection;
    IStructuredSelection currentStructuredSelection;

    /* Get the current selection. */
    IWorkbenchWindow window =
        ModelBusUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
    currentSelection = window.getSelectionService().getSelection();

    if (currentSelection instanceof IStructuredSelection) {
      currentStructuredSelection = (IStructuredSelection) currentSelection;
    } else {
      currentStructuredSelection = null;
    }

    /* Initialize and start the depending code gen wizard. */
    wizard = new LoadModelInstanceWizard();
    wizard.init(window.getWorkbench(), currentStructuredSelection);

    /* Instantiates the wizard container with the wizard and opens it. */
    dialog = new WizardDialog(window.getShell(), wizard);
    dialog.create();
    dialog.open();

    return null;
  }
 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
   if (activeWorkbenchWindow != null) {
     WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
     if (page != null) {
       Map parameters = event.getParameters();
       String value =
           (String) parameters.get(IWorkbenchCommandConstants.WINDOW_CLOSE_PERSPECTIVE_PARM_ID);
       if (value == null) {
         page.closePerspective(page.getPerspective(), true, true);
       } else {
         IPerspectiveDescriptor perspective =
             activeWorkbenchWindow
                 .getWorkbench()
                 .getPerspectiveRegistry()
                 .findPerspectiveWithId(value);
         if (perspective != null) {
           page.closePerspective(perspective, true, true);
         }
       }
     }
   }
   return null;
 }
예제 #8
0
 /**
  * @see
  *     org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
  */
 public Object execute(final ExecutionEvent executionEvent) throws ExecutionException {
   final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(executionEvent);
   final NewTriggerWizard wizard = new NewTriggerWizard();
   wizard.init(window.getWorkbench(), StructuredSelection.EMPTY);
   final WizardDialog wizardDialog = new STEMWizardDialog(window.getShell(), wizard);
   wizardDialog.open();
   return null;
 } // execute
  /**
   * Restart the workbench using the specified path as the workspace location.
   *
   * @param path the location
   * @since 3.3
   */
  private void restart(String path) {
    String command_line = buildCommandLine(path);
    if (command_line == null) {
      return;
    }

    System.setProperty(PROP_EXIT_CODE, Integer.toString(24));
    System.setProperty(PROP_EXIT_DATA, command_line);
    window.getWorkbench().restart();
  }
 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   ISelection selection = win.getSelectionService().getSelection();
   List<EObject> context = PapyrusSelectionManager.getESelection(selection);
   EObject selectedEObject = context.get(0);
   String metamodel = ((EPackage) selectedEObject.eClass().eContainer()).getNsURI();
   String contextType = selectedEObject.eClass().getInstanceClass().getSimpleName();
   NewRefactoringWizardJava wizard = new NewRefactoringWizardJava(metamodel, contextType);
   wizard.init(win.getWorkbench(), (IStructuredSelection) selection);
   WizardDialog dialog = new WizardDialog(win.getShell(), wizard);
   return dialog.open();
 }
예제 #11
0
 /**
  * Create a new <code>OpenPreferenceAction</code> and initialize it from the given resource
  * bundle.
  *
  * @param window
  */
 public OpenPreferencesAction(IWorkbenchWindow window) {
   super(WorkbenchMessages.get().OpenPreferences_text);
   if (window == null) {
     throw new IllegalArgumentException();
   }
   this.workbenchWindow = window;
   // @issue action id not set
   setToolTipText(WorkbenchMessages.get().OpenPreferences_toolTip);
   window
       .getWorkbench()
       .getHelpSystem()
       .setHelp(this, IWorkbenchHelpContextIds.OPEN_PREFERENCES_ACTION);
 }
예제 #12
0
  @Before
  public void setUp() throws Exception {
    tearDown();

    wizard = createNewProjectWizard();
    IWorkbenchWindow window = WorkbenchUtils.getActiveWorkbenchWindow();
    wizard.init(window.getWorkbench(), null);

    Shell parent = WorkbenchUtils.getActiveWorkbenchShell();
    wizDialog = new WizardDialog__Accessor(parent, wizard);
    wizDialog.setBlockOnOpen(false);
    wizDialog.open();
  }
예제 #13
0
  public int open() {
    IWorkbench workbench = window.getWorkbench();
    bindingService = (IBindingService) workbench.getAdapter(IBindingService.class);
    contextService = (IContextService) workbench.getAdapter(IContextService.class);
    if (bindingService != null) {
      registerWorkbenchCommands();
    }
    int ret = super.open();
    if (ret == OK) {
      if (contextService != null) {
        contextActivation = contextService.activateContext(CONTEXT_ID);
      }
      if (bindingService != null) {
        registerDialogCommands();
      }
    }
    activateJob();

    return ret;
  }
예제 #14
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
   * .ExecutionEvent)
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWindow != null) {
      FileDialog dlg = new FileDialog(Display.getDefault().getActiveShell(), SWT.MULTI);

      String initialDirData = SampleNavigatorView.getInitialDirectory();
      dlg.setFilterPath(initialDirData);
      String selectedDirectory = dlg.open();
      if (selectedDirectory != null) {
        int index = selectedDirectory.lastIndexOf(System.getProperty("file.separator"));
        if (index > 0) {
          selectedDirectory = selectedDirectory.substring(0, index);
        }
        String files[] = dlg.getFileNames();

        if (selectedDirectory != null && files != null) {
          try {
            activeWindow.getWorkbench().showPerspective(Perspective.ID, activeWindow);
            SampleNavigatorView sampleView =
                (SampleNavigatorView)
                    PlatformUI.getWorkbench()
                        .getActiveWorkbenchWindow()
                        .getActivePage()
                        .findView(SampleNavigatorView.ID);

            sampleView.addFiles(files, selectedDirectory);
          } catch (WorkbenchException ex) {
            FableUtils.excMsg(this, "ImageViewer cannot be opened", ex);
          }
        }
      }
    }

    // Must currently be null
    return null;
  }
예제 #15
0
  public void testScopedService() throws Exception {
    IWorkbenchWindow window = openTestWindow();
    IEvaluationService service = (IEvaluationService) window.getService(IEvaluationService.class);
    assertNotNull(service);
    assertTrue(service instanceof SlaveEvaluationService);

    MyEval listener = new MyEval();
    IContextActivation context1 = null;
    IContextService contextService = null;
    try {
      service.addEvaluationListener(
          new ActiveContextExpression(CONTEXT_ID1, new String[] {ISources.ACTIVE_CONTEXT_NAME}),
          listener,
          IEvaluationService.RESULT);
      assertEquals(1, listener.count);
      assertFalse(listener.currentValue);

      contextService = (IContextService) window.getWorkbench().getService(IContextService.class);
      context1 = contextService.activateContext(CONTEXT_ID1);
      assertEquals(2, listener.count);
      assertTrue(listener.currentValue);

      window.close();
      processEvents();
      assertEquals(3, listener.count);
      assertTrue(listener.currentValue);

      contextService.deactivateContext(context1);
      context1 = null;
      assertEquals(3, listener.count);
      assertTrue(listener.currentValue);
    } finally {
      if (context1 != null) {
        contextService.deactivateContext(context1);
      }
    }
  }
    @Override
    public void historyNotification(final OperationHistoryEvent event) {
      IWorkbenchWindow workbenchWindow = getWorkbenchWindow();
      if (workbenchWindow == null) return;

      Display display = workbenchWindow.getWorkbench().getDisplay();
      if (display == null) return;

      switch (event.getEventType()) {
        case OperationHistoryEvent.OPERATION_ADDED:
        case OperationHistoryEvent.OPERATION_REMOVED:
        case OperationHistoryEvent.UNDONE:
        case OperationHistoryEvent.REDONE:
          if (event.getOperation().hasContext(undoContext)) {
            display.asyncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    update();
                  }
                });
          }
          break;
        case OperationHistoryEvent.OPERATION_NOT_OK:
          if (event.getOperation().hasContext(undoContext)) {
            display.asyncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    if (pruning) {
                      IStatus status = event.getStatus();
                      /*
                       * Prune the history unless we can determine
                       * that this was a cancelled attempt. See
                       * https://bugs.eclipse.org/bugs/show_bug.cgi?id=101215
                       */
                      if (status == null || status.getSeverity() != IStatus.CANCEL) {
                        flush();
                      }
                      // not all flushes will trigger an update so
                      // force it here
                      update();
                    } else {
                      update();
                    }
                  }
                });
          }
          break;
        case OperationHistoryEvent.OPERATION_CHANGED:
          if (event.getOperation() == getOperation()) {
            display.asyncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    update();
                  }
                });
          }
          break;
      }
    }
  /**
   * @see org.eclipse.jface.action.IAction#run()
   * @since 5.0
   */
  @Override
  public void run() {
    final IWorkbenchWindow iww = VdbUiPlugin.singleton.getCurrentWorkbenchWindow();
    // A) get the selected model and extract a "ConnectionProfileInfo" from it using the
    // ConnectionProfileInfoHandler

    // B) Use ConnectionProfileHandler.getConnectionProfile(connectionProfileInfo) to query the user
    // to
    // select a ConnectionProfile (or create new one)

    // C) Get the resulting ConnectionProfileInfo from the dialog and re-set the model's connection
    // info
    // via the ConnectionProfileInfoHandler
    ModelResource modelResource = null;
    if (!getSelection().isEmpty()) {
      IFile modelFile = (IFile) SelectionUtilities.getSelectedObjects(getSelection()).get(0);
      modelResource = ModelUtilities.getModelResource(modelFile);
    }
    try {

      ITeiidServer teiidServer = cachedServer;
      if (teiidServer == null) {
        if (DqpPlugin.getInstance().getServerManager().getDefaultServer() == null) {
          MessageDialog.openConfirm(
              iww.getShell(),
              getString("noServer.title"), // $NON-NLS-1$
              getString("noServer.message")); // $NON-NLS-1$
          return;
        } else if (DqpPlugin.getInstance().getServerManager().getDefaultServer().isConnected()) {
          teiidServer = DqpPlugin.getInstance().getServerManager().getDefaultServer();
        } else {
          MessageDialog.openConfirm(
              iww.getShell(),
              getString("noServerConnection.title"), // $NON-NLS-1$
              getString("noServerConnection.message")); // $NON-NLS-1$
          return;
        }

        teiidServer.connect();
      }

      Collection<ModelResource> relationalModels = getRelationalModelsWithConnections();
      final CreateDataSourceWizard wizard =
          new CreateDataSourceWizard(teiidServer, relationalModels, modelResource);

      wizard.init(iww.getWorkbench(), new StructuredSelection());
      final WizardDialog dialog = new WizardDialog(wizard.getShell(), wizard);
      final int rc = dialog.open();
      if (rc == Window.OK) {
        // Need to check if the connection needs a password

        TeiidDataSourceInfo info = wizard.getTeiidDataSourceInfo();
        Properties props = info.getProperties();
        IConnectionInfoProvider provider = info.getConnectionInfoProvider();
        boolean cancelledPassword = false;
        if (null != provider.getDataSourcePasswordPropertyKey()
            && props.get(provider.getDataSourcePasswordPropertyKey()) == null) {

          int result =
              new AbstractPasswordDialog(
                  iww.getShell(), getString("passwordTitle"), null) { // $NON-NLS-1$
                @SuppressWarnings("synthetic-access")
                @Override
                protected boolean isPasswordValid(final String password) {
                  pwd = password;
                  return true;
                }
              }.open();
          if (result == Window.OK) {
            props.put(provider.getDataSourcePasswordPropertyKey(), this.pwd);
          } else {
            cancelledPassword = true;
          }
        }

        if (!cancelledPassword) {
          teiidServer.getOrCreateDataSource(
              info.getDisplayName(), info.getJndiName(), provider.getDataSourceType(), props);
        }
      }
      // createDataSource(modelFile);
    } catch (Exception e) {
      if (modelResource != null) {
        MessageDialog.openError(
            getShell(),
            getString("errorCreatingDataSourceForModel", modelResource.getItemName()),
            e.getMessage()); // $NON-NLS-1$
        DqpUiConstants.UTIL.log(
            IStatus.ERROR,
            e,
            getString(
                "errorCreatingDataSourceForModel", modelResource.getItemName())); // $NON-NLS-1$
      } else {
        MessageDialog.openError(
            getShell(), getString("errorCreatingDataSource"), e.getMessage()); // $NON-NLS-1$
        DqpUiConstants.UTIL.log(
            IStatus.ERROR, e, getString("errorCreatingDataSource")); // $NON-NLS-1$
      }
    }
  }