Пример #1
0
 /**
  * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
  * @param element
  * @return
  */
 public String getText(Object element) {
   if (element instanceof View) {
     EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) element);
     if (dummyEP instanceof ILabelRoleProvider) {
       return ((ILabelRoleProvider) dummyEP).getLabelRole();
     }
   }
   return "";
 }
Пример #2
0
 /** {@inheritDoc} */
 @Override
 public String getLabel() {
   if (getRepresentedEditPart() != null) {
     return getRepresentedEditPart().getCompartmentName();
   } else {
     EditPart dummyEP =
         EditPartService.getInstance().createGraphicEditPart(getCompartmentView());
     if (dummyEP instanceof IResizableCompartmentEditPart) {
       return ((IResizableCompartmentEditPart) dummyEP).getCompartmentName();
     }
   }
   return getEditorLabelProvider().getText(getCompartmentView());
 }
  /**
   * initialize the status of the compartment for the node (Showed or hidden)
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initCompartmentsStatusFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    EList<?> children = view.getPersistedChildren();
    if (children != null) {
      for (Object object : children) {

        // we look for the name of the compartment for this view
        EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) object);
        IGraphicalEditPart epp = (IGraphicalEditPart) dummyEP;
        IFigure fig1 = epp.getFigure();

        if (fig1 instanceof ResizableCompartmentFigure) {
          String compartmentName = ((ResizableCompartmentFigure) fig1).getCompartmentTitle();
          if (compartmentName != null) {
            String diagramKind = view.getDiagram().getType();
            String preferenceKey =
                PreferenceConstantHelper.getCompartmentElementConstant(
                    diagramKind + "_" + elementName,
                    compartmentName,
                    PreferenceConstantHelper.COMPARTMENT_VISIBILITY); // $NON-NLS-1$
            boolean value = store.getBoolean(preferenceKey);

            if (!value) { // the default value is true : nothing to
              // do
              ENamedElement namedElement =
                  PackageUtil.getElement("notation.View.visible"); // $NON-NLS-1$
              ViewUtil.setStructuralFeatureValue(
                  (View) object, (EStructuralFeature) namedElement, value);
            }

            String compartmentNameVisibilityPreference =
                PreferenceConstantHelper.getCompartmentElementConstant(
                    diagramKind + "_" + elementName,
                    compartmentName,
                    PreferenceConstantHelper.COMPARTMENT_NAME_VISIBILITY); // $NON-NLS-1$
            boolean showCompartmentName = store.getBoolean(compartmentNameVisibilityPreference);
            View childView = (View) object;
            TitleStyle style =
                (TitleStyle) childView.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
            if (style != null) {
              style.setShowTitle(showCompartmentName);
            }
          }
        }
        dummyEP = null;
      }
    }
  }
  /**
   * initialize the status of each label for the node or for the link (Showed or hidden)
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initLabelVisibilityFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    EList<?> children = view.getPersistedChildren();
    if (children != null) {
      for (Object object : children) {

        // we look for the name of the label for this view
        EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) object);
        if (dummyEP instanceof ILabelRoleProvider) {
          String role = ((ILabelRoleProvider) dummyEP).getLabelRole();
          String diagramKind = view.getDiagram().getType();
          String key =
              PreferenceConstantHelper.getLabelElementConstant(
                  diagramKind + "_" + elementName,
                  role,
                  PreferenceConstantHelper.LABEL_VISIBILITY); // $NON-NLS-1$
          ((View) object).setVisible(store.getBoolean(key));
        }
        dummyEP = null;
      }
    }
  }
Пример #5
0
 /**
  * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
  * @param element
  * @return
  */
 public Image getImage(Object element) {
   if (element instanceof View) {
     EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) element);
     String iconPath = "";
     if (dummyEP instanceof ILabelRoleProvider) {
       iconPath = ((ILabelRoleProvider) dummyEP).getIconPathRole();
       if (iconPath != null) {
         if (iconPath.indexOf("platform") == 0) {
           // the path looks like
           // "platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Package.gif"
           try {
             return ImageDescriptor.createFromURL(new URL(iconPath)).createImage();
           } catch (MalformedURLException e) {
             Activator.log.error("I can't find the following image " + iconPath, e);
             return null;
           }
         }
       }
     }
   }
   return null;
 }
 /** @param input */
 private void setInput(Object input) {
   Diagram diagram = null;
   if (input instanceof Pageflow) {
     Pageflow pageflow = (Pageflow) input;
     diagram = fetchDiagram(pageflow.eResource());
   } else if (input instanceof Diagram) {
     diagram = (Diagram) input;
   } else if (input instanceof Resource) {
     Resource res = (Resource) input;
     diagram = fetchDiagram(res);
   } else if (input instanceof ResourceSet) {
     Resource res = ((ResourceSet) input).getResources().get(0);
     diagram = fetchDiagram(res);
   } else if (input instanceof List) {
     Resource res = (Resource) ((List<?>) input).get(0);
     diagram = fetchDiagram(res);
   }
   if (diagram != null) {
     TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(
         diagram.eResource().getResourceSet());
     RootEditPart rootEP = EditPartService.getInstance().createRootEditPart(diagram);
     if (rootEP instanceof DiagramRootEditPart) {
       ((DiagramRootEditPart) rootEP)
           .setPreferencesHint(PageflowDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
     }
     viewer.setRootEditPart(rootEP);
     viewer.setEditPartFactory(new PageflowEditPartFactory());
     viewer.setContents(diagram);
     viewer.flush();
     if (viewer.getContents() instanceof DiagramEditPart) {
       DiagramEditPart dp = (DiagramEditPart) viewer.getContents();
       dp.disableEditMode();
     }
   }
   return;
 }