Esempio n. 1
0
  /*
   * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
   */
  public void setDocument(
      IDocument document,
      IAnnotationModel annotationModel,
      int modelRangeOffset,
      int modelRangeLength) {
    disposeVisualAnnotationModel();

    if (annotationModel != null && document != null) {
      fVisualAnnotationModel = createVisualAnnotationModel(annotationModel);
      fVisualAnnotationModel.connect(document);
    }

    if (modelRangeOffset == -1 && modelRangeLength == -1) super.setDocument(document);
    else super.setDocument(document, modelRangeOffset, modelRangeLength);

    if (fVerticalRuler != null) fVerticalRuler.setModel(fVisualAnnotationModel);

    if (fOverviewRuler != null) fOverviewRuler.setModel(fVisualAnnotationModel);
  }
  /** @see IWorkbenchPart#createPartControl */
  public void createPartControl(Composite parent) {
    viewer = new TextViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.READ_ONLY);
    viewer.setDocument(new Document());

    IActionBars bars = getViewSite().getActionBars();

    final GlobalAction clearOutputAction = new ClearTextAction(viewer.getDocument());
    clearOutputAction.registerAsGlobalAction(bars);

    final GlobalAction selectAllAction = new SelectAllAction(viewer);
    selectAllAction.registerAsGlobalAction(bars);

    // Delete action shortcuts are not captured by the workbench
    // so we need our key binding service to handle Delete keystrokes for us
    this.viewer
        .getControl()
        .addKeyListener(
            new KeyAdapter() {
              public void keyPressed(KeyEvent e) {
                if (e.character == SWT.DEL) clearOutputAction.run();
              }
            });

    GlobalAction copyAction = new CopyTextSelectionAction(viewer);
    copyAction.registerAsGlobalAction(bars);

    bars.getToolBarManager().add(clearOutputAction);

    bars.updateActionBars();

    // creates a context menu with actions and adds it to the viewer control
    MenuManager menuMgr = new MenuManager();
    menuMgr.add(copyAction);
    menuMgr.add(clearOutputAction);
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);

    getViewSite().getPage().addSelectionListener(this);
  }
Esempio n. 3
0
  @Override
  public void createPartControl(Composite parent) {
    // add controls
    try {
      CWMetaInput input = (CWMetaInput) getEditorInput();
      CWScript document = new CWScript(input.getRootElement());
      List<CWParameter> documentParameters = document.getParameterList();
      String documentScript = document.getScript();

      /*GridLayout layout = new GridLayout();
      layout.numColumns = 1;
      parent.setLayout(layout);*/
      parent.setLayout(new FillLayout(SWT.VERTICAL));

      SashForm sashForm = new SashForm(parent, SWT.VERTICAL);

      // setup table
      final TableViewer tableViewer =
          new TableViewer(
              sashForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);

      // setup name column
      TableViewerColumn colName = new TableViewerColumn(tableViewer, SWT.NONE);
      colName.getColumn().setWidth(200);
      colName.getColumn().setText("Name");
      colName.setLabelProvider(
          new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
              return ((CWParameter) element).getName();
            }
          });

      // setup value column
      TableViewerColumn colValue = new TableViewerColumn(tableViewer, SWT.NONE);
      colValue.getColumn().setWidth(200);
      colValue.getColumn().setText("Type");
      colValue.setLabelProvider(
          new ColumnLabelProvider() {
            @Override
            public String getText(Object element) {
              return ((CWParameter) element).getType();
            }
          });

      final Table table = tableViewer.getTable();
      table.setHeaderVisible(true);
      table.setLinesVisible(true);

      tableViewer.setContentProvider(ArrayContentProvider.getInstance());
      tableViewer.setInput(documentParameters);

      /*GridData gridData = new GridData();
      gridData.verticalAlignment = GridData.FILL;
      gridData.horizontalSpan = 2;
      gridData.grabExcessHorizontalSpace = true;
      gridData.grabExcessVerticalSpace = true;
      gridData.horizontalAlignment = GridData.FILL;*/
      // tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

      // setup script text area
      final TextViewer textViewer = new TextViewer(sashForm, SWT.MULTI | SWT.V_SCROLL);
      textViewer.setDocument(new Document(documentScript));

      /*gridData = new GridData();
      gridData.verticalAlignment = GridData.FILL;
      gridData.horizontalSpan = 2;
      gridData.grabExcessHorizontalSpace = true;
      gridData.grabExcessVerticalSpace = true;
      gridData.horizontalAlignment = GridData.FILL;*/
      // textViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

      sashForm.setWeights(new int[] {1, 3});

    } catch (Exception ex) {
      System.out.println(ex);
    }
  }
Esempio n. 4
0
  @Override
  protected Composite createPageContainer(Composite parent) {
    this.editorParent = parent;
    Composite composite = super.createPageContainer(parent);

    EditorUtil.initializeScrollbars(getHeaderForm().getForm());

    // create left tool bar that replaces form heading label
    try {
      FormHeading heading = (FormHeading) getHeaderForm().getForm().getForm().getHead();

      Field field = FormHeading.class.getDeclaredField("titleRegion"); // $NON-NLS-1$
      field.setAccessible(true);

      TitleRegion titleRegion = (TitleRegion) field.get(heading);

      leftToolBarManager = new ToolBarManager(SWT.FLAT);
      leftToolBar = leftToolBarManager.createControl(titleRegion);
      leftToolBar.addControlListener(
          new ControlAdapter() {
            private boolean ignoreResizeEvents;

            @Override
            public void controlResized(ControlEvent e) {
              if (ignoreResizeEvents) {
                return;
              }
              ignoreResizeEvents = true;
              try {
                // the tool bar contents has changed, update state
                updateHeaderImage();
                updateHeaderLabel();
              } finally {
                ignoreResizeEvents = false;
              }
            }
          });

      // titleLabel = new Label(titleRegion, SWT.NONE);
      // need a viewer for copy support
      TextViewer titleViewer = new TextViewer(titleRegion, SWT.READ_ONLY);
      // Eclipse 3.3 needs a document, otherwise an NPE is thrown
      titleViewer.setDocument(new Document());

      titleLabel = titleViewer.getTextWidget();
      titleLabel.setForeground(heading.getForeground());
      titleLabel.setFont(heading.getFont());
      // XXX work-around problem that causes field to maintain selection when unfocused
      titleLabel.addFocusListener(
          new FocusAdapter() {
            @Override
            public void focusLost(FocusEvent e) {
              titleLabel.setSelection(0);
            }
          });

      titleRegion.addControlListener(
          new ControlAdapter() {
            @Override
            public void controlResized(ControlEvent e) {
              // do not create busyLabel to avoid recursion
              updateSizeAndLocations();
            }
          });

      IHandlerService handlerService =
          (IHandlerService) getSite().getService(IHandlerService.class);
      if (handlerService != null) {
        textSupport = new CommonTextSupport(handlerService);
        textSupport.install(titleViewer, false);
      }
    } catch (Exception e) {
      if (!toolBarFailureLogged) {
        StatusHandler.log(
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                "Failed to obtain busy label toolbar",
                e)); //$NON-NLS-1$
      }
      if (titleLabel != null) {
        titleLabel.dispose();
        titleLabel = null;
      }
      if (leftToolBar != null) {
        leftToolBar.dispose();
        leftToolBar = null;
      }
      if (leftToolBarManager != null) {
        leftToolBarManager.dispose();
        leftToolBarManager = null;
      }
    }

    updateHeader();

    return composite;
  }