コード例 #1
0
ファイル: PartInstantiator.java プロジェクト: maduhu/earthsci
  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);
    }
  }
コード例 #2
0
 public void activateBranch() {
   for (IEclipseContext i = this; i != null; i = i.getParent()) {
     i.activate();
   }
 }