public NativeStackPresentation(Composite parent, IStackPresentationSite stackSite) {
    super(stackSite);

    tabFolder = new TabFolder(parent, tabPos);

    // listener to switch between visible tabItems
    tabFolder.addListener(SWT.Selection, selectionListener);

    // listener to resize visible components
    tabFolder.addListener(SWT.Resize, resizeListener);

    // listen for mouse down on tab to set focus.
    tabFolder.addMouseListener(mouseListener);

    tabFolder.addListener(SWT.MenuDetect, menuListener);

    dragListener =
        new Listener() {
          public void handleEvent(Event event) {
            Point localPos = new Point(event.x, event.y);
            //				TabItem tabUnderPointer = tabFolder.getItem(localPos);
            TabItem tabUnderPointer = null;

            if (tabUnderPointer == null) {
              return;
            }

            IPresentablePart part = getPartForTab(tabUnderPointer);

            if (getSite().isPartMoveable(part)) {
              getSite().dragStart(part, tabFolder.toDisplay(localPos), false);
            }
          }
        };

    PresentationUtil.addDragListener(tabFolder, dragListener);
  }
Esempio n. 2
0
  /**
   * This operation overrides the ViewPart.createPartControl method to create and draw the
   * TreeViewer before registering it as a selection provider.
   *
   * @param parent The Composite used to create the TreeViewer.
   */
  @Override
  public void createPartControl(Composite parent) {

    // Create a TabFolder to manage tabs
    tabFolder = new TabFolder(parent, SWT.NONE);

    // Create pages (TabItems) for text files and images
    TabItem textTab = new TabItem(tabFolder, SWT.NONE, 0);
    textTab.setText("Files");
    TabItem imageTab = new TabItem(tabFolder, SWT.NONE, 1);
    imageTab.setText("Images");
    TabItem plotTab = new TabItem(tabFolder, SWT.NONE, 2);
    plotTab.setText("Plots");

    // Create the tool bar and buttons for the view
    createActions();

    // Initialize the TreeViewer
    resourceTreeViewer = new TreeViewer(tabFolder);
    // Create content and label providers
    initializeTreeViewer(resourceTreeViewer);
    // Register the tree to the tabs
    textTab.setControl(resourceTreeViewer.getControl());
    imageTab.setControl(resourceTreeViewer.getControl());
    // Register this view as a SelectionProvider
    getSite().setSelectionProvider(resourceTreeViewer);
    // Registered the view as a double click listener of the TreeViewer
    resourceTreeViewer.addDoubleClickListener(this);

    // Add a listener to catch tab selection changes.
    // NOTE: In Windows, this event is fired instantly, so this listener
    // needs to be declared after everything else is initialized!
    tabFolder.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            // If tabs are changed while playing, stop playing.
            if (playAction.isInPlayState()) {
              playAction.stop();
            }
            // Set the TreeViewer input to the selected tab
            setTreeContent(tabFolder.indexOf((TabItem) event.item));
          }
        });

    // Create the Table and table viewer for the Plot tab
    Table listTable = new Table(tabFolder, SWT.FLAT);
    DefaultEventTableViewer<VizResource> listTableViewer =
        new DefaultEventTableViewer<VizResource>(plotList, listTable, plotList);
    // Register the table control with the plot tab
    plotTab.setControl(listTable);

    // Check if there is currently an active ICEFormEditor. If so, update
    // the currently active editor and related UI pieces.
    IEditorPart activeEditor =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor != null && activeEditor instanceof ICEFormEditor) {
      if (activeEditor != editor) {
        setActiveEditor((ICEFormEditor) activeEditor);
      }
    } else {
      // Get a list of all the currently open editors
      IWorkbenchPage workbenchPage =
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      IEditorReference[] editorRefs = workbenchPage.getEditorReferences();

      if (editorRefs != null && editorRefs.length > 0) {
        // Begin iterating through all the editors, looking for one
        // that's an ICEFormEditor
        for (IEditorReference e : editorRefs) {
          // If it's an ICEFormEditor, set it as the active editor
          if (e.getId().equals(ICEFormEditor.ID)) {
            setActiveEditor((ICEFormEditor) e.getEditor(false));
            break;
          }
        }
      }
    }

    // Register as a listener to the part service so that the view can
    // update when the active ICEFormEditor changes.
    IPartService partService = getSite().getWorkbenchWindow().getPartService();
    partService.addPartListener(this);

    return;
  }