@Override
 public Menu getMenu(Control parent) {
   if (menu != null) {
     menu.dispose();
   }
   Menu newMenu = new Menu(parent);
   List<String> preferenceConfigurations =
       PrologRuntimeUIPlugin.getDefault().getPreferenceConfigurations();
   String defaultConfiguration =
       PrologRuntimeUIPlugin.getDefault()
           .getPreferenceStore()
           .getString(PrologRuntimeUI.PREF_CONFIGURATION);
   for (String preferenceConfiguration : preferenceConfigurations) {
     MenuItem item = new MenuItem(newMenu, SWT.NONE);
     item.setText(preferenceConfiguration.replaceAll("&", "&&"));
     if (preferenceConfiguration.equals(defaultConfiguration)) {
       item.setImage(ImageRepository.getImage(ImageRepository.NEW_PROCESS));
     }
     final String configuration = preferenceConfiguration;
     item.addSelectionListener(
         new SelectionAdapter() {
           @Override
           public void widgetSelected(SelectionEvent e) {
             askForNameAndCreateProcess(configuration);
           }
         });
   }
   menu = newMenu;
   return menu;
 }
 @Override
 public void run() {
   askForNameAndCreateProcess(
       PrologRuntimeUIPlugin.getDefault()
           .getPreferenceStore()
           .getString(PrologRuntimeUI.PREF_CONFIGURATION));
 }
  private void setPrologInterface(PrologInterface newPif, boolean updateActivePif) {
    if (currentPif == newPif) {
      return;
    }
    if (currentPif != null) {
      viewerStates.put(currentPif, viewer.saveState());
    }
    currentPif = newPif;
    if (currentPif != null) {
      addHooks(currentPif);
      try {
        connect(currentPif);
      } catch (PrologInterfaceException e) {
        Debug.report(e);
      }
      reconfigureViewer(currentPif);
      getDefaultPrologConsoleService().fireActivePrologInterfaceChanged(this);
      if (updateActivePif) {
        PrologRuntimeUIPlugin.getDefault()
            .getPrologInterfaceService()
            .setActivePrologInterface(currentPif);
      }

    } else {
      Debug.debug("no pif (yet).");
    }
    if (automatedSelector != null) {
      automatedSelector.update();
    }
    writeCurrentProcessPortToFile();
  }
  public PrologInterface activateNewPrologProcess(
      PrologInterfaceRegistry registry, String pifKey, String configuration) {
    DefaultSubscription subscription =
        new DefaultSubscription(
            pifKey + "_indepent", pifKey, "Independent prolog process", "Prolog");
    registry.addSubscription(subscription);
    PrologInterface pif =
        PrologRuntimeUIPlugin.getDefault().getPrologInterface(subscription, configuration);

    if (automatedSelector.getActiveTrackers().isEmpty()) {
      setPrologInterface(pif);
      automatedSelector.setImageDescriptor(
          ImageRepository.getImageDescriptor(ImageRepository.MANUAL_MODE));
    }
    return pif;
  }
  private void createPartControl_impl(Composite parent) {

    this.partControl = parent;

    Listener handler =
        new Listener() {

          @Override
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Show:
              case SWT.Hide:
                getDefaultPrologConsoleService()
                    .fireConsoleVisibilityChanged(PrologConsoleView.this);
                break;
              case SWT.FocusOut:
                getDefaultPrologConsoleService().fireConsoleLostFocus(PrologConsoleView.this);
            }
          }
        };
    parent.getParent().addListener(SWT.Show, handler);
    parent.getParent().addListener(SWT.Hide, handler);
    parent.getParent().addListener(SWT.FocusOut, handler);
    PrologConsolePlugin.getDefault().getPrologConsoleService().registerPrologConsole(this);
    getDefaultPrologConsoleService().fireConsoleVisibilityChanged(PrologConsoleView.this);
    PrologRuntimeUIPlugin.getDefault()
        .getPrologInterfaceService()
        .registerActivePrologInterfaceListener(this);
    GridLayout layout = new GridLayout(1, true);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    parent.setLayout(layout);
    GridData ld = new GridData(GridData.FILL_HORIZONTAL);
    title = new Label(parent, SWT.HORIZONTAL);
    title.setLayoutData(ld);
    viewer = new ConsoleViewer(parent, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    viewer.getControl().setEnabled(false);
    ld = new GridData(GridData.FILL_BOTH);
    viewer.getControl().setLayoutData(ld);
    createActions();
    initMenus(parent);
    initToolBars();
    getSite().setSelectionProvider(viewer);
  }
 @Override
 public void dispose() {
   PrologConsolePlugin.getDefault().getPrologConsoleService().unregisterPrologConsole(this);
   PrologRuntimeUIPlugin.getDefault()
       .getPrologInterfaceService()
       .unRegisterActivePrologInterfaceListener(this);
   for (Iterator<PrologInterface> it = models.keySet().iterator(); it.hasNext(); ) {
     PrologInterface pif = it.next();
     try {
       disconnect(pif);
       removeHooks(pif);
     } catch (Throwable e) {
       Debug.report(e);
     }
   }
   models.clear();
   contextMenu.dispose();
   // viewer.getControl().dispose();
   super.dispose();
 }
Beispiel #7
0
  @Override
  public void run(IMarker marker) {

    IFile file = (IFile) marker.getResource();
    TextFileChange textFileChange = new TextFileChange(file.getName(), file);
    MultiTextEdit fileChangeRootEdit = new MultiTextEdit();

    // a file change contains a tree of edits, first add the root of them
    textFileChange.setEdit(fileChangeRootEdit);
    int offset;
    try {
      offset = marker.getAttribute(IMarker.CHAR_START, -1);
      if (offset == -1) {
        int line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
        if (line == -1) {
          return;
        }
        offset = UIUtils.getDocument(file).getLineOffset(line - 1);
      }
      InsertEdit quickfix =
          new InsertEdit(offset, marker.getAttribute(PDTMarker.QUICKFIX_ACTION).toString());

      fileChangeRootEdit.addChild(quickfix);

      if (showWizard) {
        final TextFileChange fChange = textFileChange;
        Refactoring ref =
            new Refactoring() {

              @Override
              public String getName() {
                return "PDT Refactoring";
              }

              @Override
              public Change createChange(IProgressMonitor pm)
                  throws CoreException, OperationCanceledException {
                return fChange;
              }

              @Override
              public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
                  throws CoreException, OperationCanceledException {
                return new RefactoringStatus();
              }

              @Override
              public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
                  throws CoreException, OperationCanceledException {
                return new RefactoringStatus();
              }
            };
        RefactoringWizard wizard =
            new RefactoringWizard(ref, RefactoringWizard.WIZARD_BASED_USER_INTERFACE) {

              @Override
              protected void addUserInputPages() {}
            };
        Shell shell = UIUtils.getActiveShell();
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        try {
          if (op.run(shell, "") != IDialogConstants.CANCEL_ID) {
            // changes are already performed by the dialog
            file.refreshLocal(IResource.DEPTH_INFINITE, null);
            PrologRuntimeUIPlugin.getDefault().getPrologInterfaceService().consultFile(file);
            //						PLMarkerUtils.updateFileMarkers(file);
          }
        } catch (InterruptedException e) {
        }
      } else {
        textFileChange.perform(new NullProgressMonitor());

        file.refreshLocal(IResource.DEPTH_INFINITE, null);
        PrologRuntimeUIPlugin.getDefault().getPrologInterfaceService().consultFile(file);
        //				PLMarkerUtils.updateFileMarkers(file);
      }
    } catch (NumberFormatException e1) {
      Debug.report(e1);
    } catch (CoreException e1) {
      Debug.report(e1);
    } catch (BadLocationException e) {
      Debug.report(e);
    }
  }
  private void createAutomatedSelector(IToolBarManager toolBarManager) {

    automatedSelector =
        new SelectContextPIFAutomatedAction() {

          @Override
          protected PrologInterface getPrologInterface() {
            return PrologConsoleView.this.getPrologInterface();
          }

          @Override
          protected void setPrologInterface(PrologInterface prologInterface) {
            PrologConsoleView.this.setPrologInterface(prologInterface);
          }

          @Override
          protected void trackerActivated(PrologContextTracker tracker) {
            setPrologInterface(automatedSelector.getCurrentPrologInterface());
          }

          @Override
          protected void trackerDeactivated(PrologContextTracker tracker) {
            setPrologInterface(automatedSelector.getCurrentPrologInterface());
          }

          @Override
          public void contextChanged(PrologContextTrackerEvent e) {
            PrologContextTracker tracker = (PrologContextTracker) e.getSource();
            Debug.info("context changed for tracker " + tracker.getLabel());
            setPrologInterface(e.getPrologInterface());
          }
        };
    toolBarManager.add(automatedSelector);

    //		pifSelector = new SelectPifAction() {
    //
    //			protected void setPrologInterface(PrologInterface prologInterface) {
    //				PrologConsoleView.this.setPrologInterface(prologInterface);
    //
    //			}
    //
    //			protected PrologInterface getPrologInterface() {
    //				return PrologConsoleView.this.getPrologInterface();
    //			}
    //
    //		};
    //		toolBarManager.add(pifSelector);

    //		contextSelector = new SelectContextsAction() {
    //
    //			public void contextChanged(PrologContextTrackerEvent e) {
    //				PrologContextTracker tracker = (PrologContextTracker) e
    //						.getSource();
    //				Debug.info("context changed for tracker " + tracker.getLabel());
    //				setPrologInterface(e.getPrologInterface());
    //
    //			}
    //
    //			protected void trackerActivated(PrologContextTracker tracker) {
    //				setPrologInterface(contextSelector.getCurrentPrologInterface());
    //
    //			}
    //
    //			protected void trackerDeactivated(PrologContextTracker tracker) {
    //				setPrologInterface(contextSelector.getCurrentPrologInterface());
    //
    //			}
    //		};

    //		toolBarManager.add(contextSelector);
    //		setPrologInterface(contextSelector.getCurrentPrologInterface());
    setPrologInterface(
        PrologRuntimeUIPlugin.getDefault().getPrologInterfaceService().getActivePrologInterface());
    automatedSelector.setImageDescriptor(
        ImageRepository.getImageDescriptor(ImageRepository.MANUAL_MODE));
  }