private void resetPerspectiveModel(
      MPerspective persp, MWindow window, boolean removeSharedPlaceholders) {
    if (persp == null) {
      return;
    }

    if (removeSharedPlaceholders) {
      // Remove any views (Placeholders) from the shared area
      EPartService ps = window.getContext().get(EPartService.class);
      List<MArea> areas = findElements(window, null, MArea.class, null);
      if (areas.size() == 1) {
        MArea area = areas.get(0);

        // Strip out the placeholders in visible stacks
        List<MPlaceholder> phList = findElements(area, null, MPlaceholder.class, null);
        for (MPlaceholder ph : phList) {
          ps.hidePart((MPart) ph.getRef());
          ph.getParent().getChildren().remove(ph);
        }

        // Prevent shared stacks ids from clashing with the ones in the perspective
        List<MPartStack> stacks = findElements(area, null, MPartStack.class, null);
        for (MPartStack stack : stacks) {
          String generatedId = "PartStack@" + Integer.toHexString(stack.hashCode()); // $NON-NLS-1$
          stack.setElementId(generatedId);
        }

        // Also remove any min/max tags on the area (or its placeholder)
        MUIElement areaPresentation = area;
        if (area.getCurSharedRef() != null) {
          areaPresentation = area.getCurSharedRef();
        }

        areaPresentation.getTags().remove(IPresentationEngine.MAXIMIZED);
        areaPresentation.getTags().remove(IPresentationEngine.MINIMIZED);
        areaPresentation.getTags().remove(IPresentationEngine.MINIMIZED_BY_ZOOM);
      }
    }

    // Remove any minimized stacks for this perspective
    List<MTrimBar> bars = findElements(window, null, MTrimBar.class, null);
    List<MToolControl> toRemove = new ArrayList<>();
    for (MTrimBar bar : bars) {
      for (MUIElement barKid : bar.getChildren()) {
        if (!(barKid instanceof MToolControl)) {
          continue;
        }
        String id = barKid.getElementId();
        if (id != null && id.contains(persp.getElementId())) {
          toRemove.add((MToolControl) barKid);
        }
      }
    }

    for (MToolControl toolControl : toRemove) {
      // Close any open fast view
      toolControl.setToBeRendered(false);
      toolControl.getParent().getChildren().remove(toolControl);
    }
  }
예제 #2
0
 @Execute
 public void execute(EPartService partService, @Named("partId") String partId) {
   MPart part = partService.findPart(partId);
   if (part == null) {
     partService.createPart(partId);
   }
   partService.activate(part);
 }
예제 #3
0
  public static void createParts(
      MApplication application, EModelService service, EPartService partService) {
    // Sometimes, when switching windows at startup, the active context
    // is null or doesn't have a window, and the part instantiation fails.
    // Ensure that a child context with a window is activated:
    IEclipseContext activeChild = application.getContext().getActiveChild();
    if (activeChild == null || activeChild.get(MTrimmedWindow.class) == null) {
      boolean activated = false;
      if (application.getContext() instanceof EclipseContext) {
        for (IEclipseContext child : ((EclipseContext) application.getContext()).getChildren()) {
          MTrimmedWindow window = child.get(MTrimmedWindow.class);
          if (window != null) {
            child.activate();
            activated = true;
            break;
          }
        }
      }
      if (!activated) {
        logger.error("Could not activate window for part instantiation"); // $NON-NLS-1$
        return;
      }
    }

    List<MPart> ontops = new ArrayList<MPart>();
    for (MPartDescriptor descriptor : application.getDescriptors()) {
      if (!(descriptor.getPersistedState().containsKey(VISIBLE_ID)
          && Boolean.toString(true)
              .equalsIgnoreCase(descriptor.getPersistedState().get(VISIBLE_ID)))) {
        continue;
      }
      List<MPart> existingParts =
          service.findElements(application, descriptor.getElementId(), MPart.class, null);
      if (!existingParts.isEmpty()) {
        // part is already instantiated
        continue;
      }
      MPart part = partService.createPart(descriptor.getElementId());
      if (part == null) {
        continue;
      }
      addPartToAppropriateContainer(part, descriptor, application, service);
      partService.activate(part);
      if (descriptor.getPersistedState().containsKey(ONTOP_ID)
          && Boolean.toString(true)
              .equalsIgnoreCase(descriptor.getPersistedState().get(ONTOP_ID))) {
        ontops.add(part);
      }
    }

    // reactivate ontop parts to ensure they are on-top
    for (MPart ontop : ontops) {
      partService.activate(ontop);
    }
  }
예제 #4
0
  private void setComboList() {

    int index = cCombo.getSelectionIndex();
    if (index < 0) index = 0; // default selection is "NO OVERLAY"
    String text = cCombo.getText();

    ArrayList<String> itemList = new ArrayList<String>(10);
    itemList.add(IConstant.NO_OVERLAY);

    Collection<MPart> parts = partService.getParts();
    for (MPart part : parts) {
      if (isOverlayPart(part)) {
        if (part.getContext() != null) { // part is instantiated
          itemList.add(part.getLabel());
        }
      }
    }

    String[] items = itemList.toArray(new String[0]);
    cCombo.setItems(items);
    if (index > 0) {
      int newIndex = 0;
      for (int i = 1; i < items.length; i++) {
        if (text.equals(items[i])) {
          newIndex = i;
          break;
        }
      }
      index = newIndex;
    }
    cCombo.select(index);
    ((GcodeViewPart) part.getObject())
        .getGcodeViewGroup()
        .setOverlayGcodeProgram(getSelectedProgram(cCombo.getText()));
  }
 @Test
 public void testFocusChangesOnExplicitPartActivation() {
   assertFalse(((PartBackend) part.getObject()).text1.isFocusControl());
   eps.activate(part);
   processEvents();
   assertTrue(((PartBackend) part.getObject()).text1.isFocusControl());
 }
 @Ignore
 @Test
 public void XXXtestNoFocusChangeOnExplicitWidgetSelection() {
   assertFalse(((PartBackend) part.getObject()).text1.isFocusControl());
   ((TextField) toolControl.getObject()).text.setFocus();
   processEvents();
   assertEquals(part.getElementId(), eps.getActivePart().getElementId());
   assertFalse(((PartBackend) part.getObject()).text1.isFocusControl());
   assertTrue(((TextField) toolControl.getObject()).text.isFocusControl());
 }
예제 #7
0
 private void switchPerspective(MPerspective perspective) {
   if (perspective.isToBeRendered() && perspective.getWidget() == null)
     engine.createGui(perspective);
   partService.switchPerspective(perspective);
   this.activePerspective = perspective;
   if (perspective.getElementId() != null) {
     String perspectiveId = perspective.getElementId().trim();
     application.getContext().set("activePerspective", perspectiveId);
   }
 }
예제 #8
0
 @Execute
 public void execute(@Named(PARAMTER_ID) String param, EPartService partService) {
   //	public void execute(EPartService partService) {
   //		String param="next";
   MPart part = partService.getActivePart();
   Object obj = part.getObject();
   if (obj instanceof WaveformViewer) {
     if ("next".equalsIgnoreCase(param)) ((WaveformViewer) obj).moveCursor(GotoDirection.NEXT);
     else if ("prev".equalsIgnoreCase(param))
       ((WaveformViewer) obj).moveCursor(GotoDirection.PREV);
   }
 }
  @Test
  public void testNoActivationOnExplicitInPartWidgetSelection() {
    assertTrue(eps.getActivePart() == otherPart);
    assertTrue(((PartBackend) otherPart.getObject()).text1.isFocusControl());

    final boolean[] changed = new boolean[] {false};
    eps.addPartListener(
        new IPartListener() {
          @Override
          public void partVisible(MPart part) {
            changed[0] = true;
          }

          @Override
          public void partHidden(MPart part) {
            changed[0] = true;
          }

          @Override
          public void partDeactivated(MPart part) {
            changed[0] = true;
          }

          @Override
          public void partBroughtToTop(MPart part) {
            changed[0] = true;
          }

          @Override
          public void partActivated(MPart part) {
            changed[0] = true;
          }
        });

    ((PartBackend) otherPart.getObject()).text2.setFocus();
    processEvents();
    assertTrue(((PartBackend) otherPart.getObject()).text2.isFocusControl());
    assertFalse(changed[0]);
  }
예제 #10
0
  @PostConstruct
  public void postConstruct(Composite parent) {
    devicesGroupsView = partService.findPart("dec-rcp.part.devices.groups");
    devicesView = partService.findPart("dec-rcp.part.devices.list");
    sensorsView = partService.findPart("dec-rcp.part.devices.sensors");

    FilterMatcher matcher = new FilterMatcher();
    FilteredTable table =
        new FilteredTable(
            parent,
            SWT.SINGLE | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION,
            matcher,
            true);
    viewer = table.getViewer();
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer
        .getTable()
        .addSelectionListener(
            new SensorsViewerSelectionListener(
                viewer,
                devicesGroupsView,
                devicesView,
                sensorsView,
                partService,
                selectionService,
                context));

    TableViewerColumn idColumnViewer = new TableViewerColumn(viewer, SWT.NONE);
    idColumnViewer.getColumn().setWidth(50);
    idColumnViewer.getColumn().setText("#");
    idColumnViewer.setLabelProvider(new IDColumnLabelProvider(viewer));

    TableViewerColumn deviceGroupsNameColumnViewer = new TableViewerColumn(viewer, SWT.NONE);
    deviceGroupsNameColumnViewer.getColumn().setWidth(800);
    deviceGroupsNameColumnViewer.getColumn().setText("Sensor Name");
    deviceGroupsNameColumnViewer.setLabelProvider(new NameColumnLabelProvider(viewer));
    viewer.getTable().setHeaderVisible(true);
  }
예제 #11
0
  private IGcodeProgram getSelectedProgram(String text) {

    LOG.debug("getSelectedProgram: text=" + text);

    Collection<MPart> parts = partService.getParts();
    for (MPart part : parts) {
      if (isOverlayPart(part)) {
        if (text.equals(part.getLabel())) {
          final IEclipseContext context = part.getContext();
          if (context != null) return context.get(IGcodeProgram.class);
        }
      }
    }

    // if part is not instantiated and therefore gcode program is not loaded, then we are here
    return null;
  }
예제 #12
0
  @SuppressWarnings("unchecked")
  public void exchange() {
    MPart activeEditor = partService.getActivePart();

    MElementContainer<MUIElement> oldEditorStack = activeEditor.getParent();
    MElementContainer<MUIElement> splitSash = oldEditorStack.getParent();
    if (splitSash.getChildren().size() != 2) {
      return;
    }

    int oldStackIndex = splitSash.getChildren().indexOf(oldEditorStack);
    MElementContainer<MUIElement> newEditorStack =
        (MElementContainer<MUIElement>) splitSash.getChildren().get(oldStackIndex == 1 ? 0 : 1);

    exchange_editor_with_selected_in_new_stack(activeEditor, oldEditorStack, newEditorStack);

    activate(activeEditor);
  }
예제 #13
0
 private void activate(final MPart newPart) {
   partService.activate(newPart);
 }
예제 #14
0
  @Before
  public void setUp() throws Exception {
    appContext = E4Application.createDefaultContext();
    appContext.set(E4Workbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI);

    ems = appContext.get(EModelService.class);

    window = ems.createModelElement(MWindow.class);
    window.setWidth(500);
    window.setHeight(500);

    MPartSashContainer sash = ems.createModelElement(MPartSashContainer.class);
    window.getChildren().add(sash);
    window.setSelectedElement(sash);

    MPartStack stack = ems.createModelElement(MPartStack.class);
    sash.getChildren().add(stack);
    sash.setSelectedElement(stack);

    part = ems.createModelElement(MPart.class);
    part.setElementId("Part");
    part.setLabel("Part");
    part.setToolbar(ems.createModelElement(MToolBar.class));
    part.setContributionURI(Activator.asURI(PartBackend.class));
    stack.getChildren().add(part);

    toolControl = ems.createModelElement(MToolControl.class);
    toolControl.setElementId("ToolControl");
    toolControl.setContributionURI(Activator.asURI(TextField.class));
    part.getToolbar().getChildren().add(toolControl);

    stack = ems.createModelElement(MPartStack.class);
    sash.getChildren().add(stack);
    sash.setSelectedElement(stack);

    otherPart = ems.createModelElement(MPart.class);
    otherPart.setElementId("OtherPart");
    otherPart.setLabel("OtherPart");
    otherPart.setContributionURI(Activator.asURI(PartBackend.class));
    stack.getChildren().add(otherPart);

    MApplication application = ems.createModelElement(MApplication.class);
    application.getChildren().add(window);
    application.setContext(appContext);
    appContext.set(MApplication.class, application);

    wb = new E4Workbench(application, appContext);
    wb.createAndRunUI(window);

    eps = window.getContext().get(EPartService.class);
    // ensure the parts are populated and the contributions instantiated
    eps.activate(part);
    eps.activate(otherPart);
    processEvents();

    // ensure our model backend objects are created
    assertNotNull(part.getObject());
    assertNotNull(toolControl.getObject());
    assertNotNull(otherPart.getObject());

    assertNotNull(part.getWidget());
    assertNotNull(toolControl.getWidget());
    assertNotNull(otherPart.getWidget());

    // ensure focus is set to otherPart.text1
    eps.activate(otherPart);
    processEvents();
    assertTrue(((PartBackend) otherPart.getObject()).text1.isFocusControl());
  }
 @Execute
 public void execute(MApplication app, EPartService partService, EModelService modelService) {
   MPerspective element = (MPerspective) modelService.find(PART_ID, app);
   partService.switchPerspective(element);
 }