Exemplo n.º 1
0
 @Override
 public void activate(Control mapControl) {
   mapControl.addMouseListener(this);
   mapControl.addMouseMoveListener(this);
   mapControl.addMouseWheelListener(this);
   mapControl.addKeyListener(this);
 }
  /** When a console page is initialized, */
  public void init(IPageBookViewPage page, final IConsole console) {
    if (!(console instanceof ProcessConsole)) {
      return;
    }
    ProcessConsole processConsole = (ProcessConsole) console;
    IProcess process = processConsole.getProcess();
    if (process == null) {
      return;
    }
    if (!PyCodeCompletionPreferencesPage.useCodeCompletion()
        || !PyCodeCompletionPreferencesPage.useCodeCompletionOnDebug()) {
      return;
    }
    String attribute = process.getAttribute(Constants.PYDEV_DEBUG_IPROCESS_ATTR);
    if (!Constants.PYDEV_DEBUG_IPROCESS_ATTR_TRUE.equals(attribute)) {
      // Only provide code-completion for pydev debug processes.
      return;
    }
    Control control = page.getControl();
    if (page instanceof IOConsolePage) {

      // Note that completions on "all letters and '_'" are already activated just by installing
      // the content assist, but the completions on the default keybinding is not, so, we have to
      // call it ourselves here.
      control.addKeyListener(
          new KeyListener() {
            public void keyPressed(KeyEvent e) {

              if (KeyBindingHelper.matchesContentAssistKeybinding(e)) {
                contentAssist.showPossibleCompletions();
              }
            }

            public void keyReleased(KeyEvent e) {}
          });

      IOConsolePage consolePage = (IOConsolePage) page;
      TextConsoleViewer viewer = consolePage.getViewer();

      contentAssist =
          new PyContentAssistant() {
            public String showPossibleCompletions() {
              // Only show completions if we're in a suspended console.
              if (getCurrentSuspendedPyStackFrame(console) == null) {
                return null;
              }
              return super.showPossibleCompletions();
            };
          };
      contentAssist.setInformationControlCreator(
          PyContentAssistant.createInformationControlCreator(viewer));
      ILaunch launch = process.getLaunch();
      IDebugTarget debugTarget = launch.getDebugTarget();
      IInterpreterInfo projectInterpreter = null;
      if (debugTarget instanceof PyDebugTarget) {
        PyDebugTarget pyDebugTarget = (PyDebugTarget) debugTarget;
        PythonNature nature = PythonNature.getPythonNature(pyDebugTarget.project);
        if (nature != null) {
          try {
            projectInterpreter = nature.getProjectInterpreter();
          } catch (Throwable e1) {
            Log.log(e1);
          }
        }
      }
      contentAssist.install(new ScriptConsoleViewerWrapper(viewer, projectInterpreter));

      PydevConsoleInterpreter interpreter = new PydevConsoleInterpreter();
      interpreter.setConsoleCommunication(new GetCompletionsInDebug());

      IContentAssistProcessor processor =
          new PydevConsoleCompletionProcessor(interpreter, contentAssist);
      contentAssist.setContentAssistProcessor(processor, IOConsolePartition.INPUT_PARTITION_TYPE);
      contentAssist.setContentAssistProcessor(processor, IOConsolePartition.OUTPUT_PARTITION_TYPE);

      contentAssist.enableAutoActivation(true);
      contentAssist.enableAutoInsert(false);
      contentAssist.setAutoActivationDelay(PyCodeCompletionPreferencesPage.getAutocompleteDelay());
    }
  }
 public void appendListenersTo(Control control) {
   control.addKeyListener(this.listener);
 }
Exemplo n.º 4
0
  protected Control bindSetHeaderTable(FormToolkit toolkit, Composite parent, final Object id) {
    final Composite panel = toolkit.createComposite(parent);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(2, false);
    zeroMargins(layout);
    panel.setLayout(layout);

    List<SetHeaderDefinition> listData;
    Object value = node.getPropertyValue(id);
    if (value instanceof List) {
      listData = (List<SetHeaderDefinition>) value;
    } else {
      listData = new ArrayList<SetHeaderDefinition>();
    }
    final SetHeaderTableView tableView = new SetHeaderTableView(listData);
    final WritableList input = tableView.getInput();

    final Runnable addAction =
        new Runnable() {
          @Override
          public void run() {
            final SetHeaderDefinition sh =
                new SetHeaderDefinition(
                    "myHeaderName",
                    new LanguageExpressionBean(CamelModelHelper.getDefaultLanguageName(), ""));
            final TableViewer viewer = tableView.getViewer();
            Refreshable refreshable =
                new Refreshable() {

                  @Override
                  public void refresh() {
                    input.add(sh);
                    viewer.setSelection(new StructuredSelection(sh));
                    Viewers.refresh(viewer);
                    layoutForm();
                    panel.layout(true, true);
                    fireNodePropertyChangedEvent(id);
                  }
                };
            SetHeaderDialog.showDialog(sh, refreshable);
          }
        };
    final Runnable editAction =
        new Runnable() {
          @Override
          public void run() {
            Activator.getLogger().debug("Starting the edit...");

            final TableViewer viewer = tableView.getViewer();
            if (!viewer.getSelection().isEmpty()) {
              IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
              Iterator iter = selection.iterator();
              while (iter.hasNext()) {
                SetHeaderDefinition sh = toSetHeaderDefinition(iter.next());
                if (sh != null) {
                  Refreshable refreshable =
                      new Refreshable() {

                        @Override
                        public void refresh() {
                          Viewers.refresh(viewer);
                          fireNodePropertyChangedEvent(id);
                        }
                      };
                  SetHeaderDialog.showDialog(sh, refreshable);
                  break;
                }
              }
            }
          }
        };
    final Runnable deleteAction =
        new Runnable() {
          @Override
          public void run() {
            TableViewer viewer = tableView.getViewer();
            if (!viewer.getSelection().isEmpty()) {
              IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
              Iterator iter = selection.iterator();
              while (iter.hasNext()) {
                SetHeaderDefinition sh = toSetHeaderDefinition(iter.next());
                if (sh != null) {
                  input.remove(sh);
                }
              }
              fireNodePropertyChangedEvent(id);
            }
          }
        };
    tableView.setDoubleClickAction(
        new RunnableAction(getClass().getName() + ".editSetHeaderDef", "Edit", editAction));

    tableView.createPartControl(panel);
    final TableViewer viewer = tableView.getViewer();
    final Control control = tableView.getControl();
    control.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite buttonPanel = toolkit.createComposite(panel);
    buttonPanel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
    buttonPanel.setLayout(new GridLayout(1, false));

    final Button add = new Button(buttonPanel, SWT.PUSH | SWT.BORDER);
    add.setText("Add");
    add.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    final Button edit = new Button(buttonPanel, SWT.PUSH | SWT.BORDER);
    edit.setText("Edit");
    edit.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    final Button delete = new Button(buttonPanel, SWT.PUSH | SWT.BORDER);
    delete.setText("Delete");
    delete.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    // backspace on list to delete
    control.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0 && e.keyCode == SWT.BS)
                || (e.stateMask == 0 && e.keyCode == SWT.DEL)) {
              deleteAction.run();
            }
          }
        });

    // enable / disable buttons
    edit.setEnabled(false);
    delete.setEnabled(false);
    viewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            boolean enabled = !event.getSelection().isEmpty();
            edit.setEnabled(enabled);
            delete.setEnabled(enabled);
          }
        });

    edit.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            editAction.run();
          }
        });

    delete.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            deleteAction.run();
          }
        });

    add.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            addAction.run();
          }
        });

    toolkit.adapt(control, true, true);
    return control;
  }
Exemplo n.º 5
0
  protected Control bindListOfValues(FormToolkit toolkit, Composite parent, final Object id) {
    final Composite panel = toolkit.createComposite(parent);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(3, false);
    zeroMargins(layout);
    panel.setLayout(layout);

    final Text name = toolkit.createText(panel, "");
    name.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final Button add = new Button(panel, SWT.PUSH | SWT.BORDER);
    add.setText("Add");
    add.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    final Button delete = new Button(panel, SWT.PUSH | SWT.BORDER);
    delete.setText("Delete");
    // delete.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    final ListViewer viewer = new ListViewer(panel, SWT.BORDER);
    viewer.setContentProvider(new ObservableListContentProvider());

    final Control control = viewer.getControl();
    control.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (control instanceof org.eclipse.swt.widgets.List) {
      org.eclipse.swt.widgets.List list = (org.eclipse.swt.widgets.List) control;
      list.setSize(400, 300);
    }

    List<String> listData;
    Object value = node.getPropertyValue(id);
    if (value instanceof List) {
      listData = (List<String>) value;
    } else {
      listData = new ArrayList<String>();
    }
    final WritableList input = new WritableList(listData, String.class);
    node.setPropertyValue(id, input);
    viewer.setInput(input);

    final Runnable addAction =
        new Runnable() {
          @Override
          public void run() {
            String p = name.getText();
            name.setText("");
            if (!input.contains(p)) {
              input.add(p);
              fireNodePropertyChangedEvent(id);

              // lets layout to make things a bit bigger if need be
              if (control instanceof org.eclipse.swt.widgets.List) {
                org.eclipse.swt.widgets.List list = (org.eclipse.swt.widgets.List) control;
                list.pack(true);
              }
              panel.layout(true, true);
              layoutForm();
            }
          }
        };
    final Runnable deleteAction =
        new Runnable() {
          @Override
          public void run() {
            if (!viewer.getSelection().isEmpty()) {
              IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
              Iterator iter = selection.iterator();
              while (iter.hasNext()) {
                String p = (String) iter.next();
                input.remove(p);
              }
              fireNodePropertyChangedEvent(id);
            }
          }
        };

    // return on entry field adds
    name.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            if (e.stateMask == 0 && e.keyCode == '\r') {
              addAction.run();
            }
          }
        });
    // backspace on list to delete
    control.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0 && e.keyCode == SWT.BS)
                || (e.stateMask == 0 && e.keyCode == SWT.DEL)) {
              deleteAction.run();
            }
          }
        });

    // enable / disable buttons
    add.setEnabled(false);
    delete.setEnabled(false);
    name.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            add.setEnabled(name.getText().length() > 0);
          }
        });
    viewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            delete.setEnabled(!event.getSelection().isEmpty());
          }
        });

    delete.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            deleteAction.run();
          }
        });

    add.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            addAction.run();
          }
        });

    toolkit.adapt(control, true, true);
    return control;
  }
 public static void recursiveKeyListener(Control c, KeyListener listener) {
   c.addKeyListener(listener);
   if (c instanceof Composite)
     for (Control child : ((Composite) c).getChildren()) recursiveKeyListener(child, listener);
 }