Ejemplo n.º 1
0
 @Test
 public void testFocusChangesOnExplicitPartActivation() {
   assertFalse(((PartBackend) part.getObject()).text1.isFocusControl());
   eps.activate(part);
   processEvents();
   assertTrue(((PartBackend) part.getObject()).text1.isFocusControl());
 }
Ejemplo n.º 2
0
 @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());
 }
  @Override
  public boolean savePart(MPart part, boolean confirm) {
    if (!part.isDirty()) {
      return true;
    }

    if (saveHandler != null) {
      return saveHandler.save(part, confirm);
    }

    Object client = part.getObject();
    try {
      ContextInjectionFactory.invoke(client, Persist.class, part.getContext());
    } catch (InjectionException e) {
      log(
          "Failed to persist contents of part",
          "Failed to persist contents of part ({0})", //$NON-NLS-1$ //$NON-NLS-2$
          part.getElementId(),
          e);
      return false;
    } catch (RuntimeException e) {
      log(
          "Failed to persist contents of part via DI", //$NON-NLS-1$
          "Failed to persist contents of part ({0}) via DI",
          part.getElementId(),
          e); //$NON-NLS-1$
      return false;
    }
    return true;
  }
Ejemplo n.º 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()));
  }
        public void selectionChanged(MPart part, Object selection) {
          selection = createCompatibilitySelection(selection);

          Object client = part.getObject();
          if (client instanceof CompatibilityPart) {
            IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart();
            notifyPostSelectionListeners(
                part.getElementId(), workbenchPart, (ISelection) selection);
          }
        }
Ejemplo n.º 6
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);
   }
 }
Ejemplo n.º 7
0
  @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]);
  }
        public void selectionChanged(MPart part, Object selection) {
          selection = createCompatibilitySelection(selection);
          context.set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);

          IEclipseContext applicationContext = application.getContext();
          if (applicationContext.getActiveChild() == context) {
            application.getContext().set(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
          }

          Object client = part.getObject();
          if (client instanceof CompatibilityPart) {
            IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart();
            notifyListeners(part.getElementId(), workbenchPart, (ISelection) selection);
          }
        }
 @Inject
 void setPart(@Optional @Named(IServiceConstants.ACTIVE_PART) final MPart part) {
   activePart = null;
   if (part != null) {
     Object client = part.getObject();
     if (client instanceof CompatibilityPart) {
       IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart();
       activePart = workbenchPart;
     } else if (client != null) {
       if (part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY) instanceof E4PartWrapper) {
         activePart = (IWorkbenchPart) part.getTransientData().get(E4PartWrapper.E4_WRAPPER_KEY);
       }
     }
   }
 }
Ejemplo n.º 10
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());
  }