@Override
  protected StandardDiagramLayout initLayoutModel() {
    StandardDiagramLayout layoutModel = null;
    try {
      String fileName = computeLayoutFileName(this.editorInput);
      if (fileName != null) {
        final XmlResourceStore resourceStore;

        if (this.editorInput instanceof IFileEditorInput) {
          IFileEditorInput fileInput = (IFileEditorInput) this.editorInput;
          IFolder layoutFolder = (IFolder) fileInput.getFile().getParent();
          IFile layoutFile = layoutFolder.getFile(fileName);
          resourceStore = new XmlResourceStore(new WorkspaceFileResourceStore(layoutFile));
        } else if (this.editorInput instanceof FileStoreEditorInput) {
          FileStoreEditorInput fileStoreInput = (FileStoreEditorInput) this.editorInput;
          IFileStore store = EFS.getStore(fileStoreInput.getURI());
          File localFile = store.toLocalFile(EFS.NONE, null);
          // if no local file is available, obtain a cached file
          if (localFile == null) localFile = store.toLocalFile(EFS.CACHE, null);
          if (localFile == null) throw new IllegalArgumentException();
          File layoutFile = new File(localFile.getParentFile(), fileName);
          resourceStore = new XmlResourceStore(new FileResourceStore(layoutFile));
        } else {
          throw new IllegalStateException();
        }

        layoutModel = StandardDiagramLayout.TYPE.instantiate(new RootXmlResource(resourceStore));
      }
    } catch (Exception e) {
      Sapphire.service(LoggingService.class).log(e);
    }

    return layoutModel;
  }
Ejemplo n.º 2
0
  @Override
  public <A> A adapt(final Class<A> adapterType) {
    A result = Sapphire.service(MasterConversionService.class).convert(this, adapterType);

    if (result == null && this.base != null) {
      result = this.base.adapt(adapterType);
    }

    return result;
  }
Ejemplo n.º 3
0
  public <A> A adapt(final Class<A> adapterType) {
    A result = Sapphire.service(MasterConversionService.class).convert(this, adapterType);

    if (result == null) {
      if (adapterType == LocalizationService.class) {
        result = adapterType.cast(getLocalizationService());
      }
    }

    return result;
  }
  @Override
  protected Object run(final Presentation context) {
    final DiagramNodePart part = (DiagramNodePart) context.part();
    final Location location = (Location) part.getModelElement();
    final String locationName = location.getName().text();

    if (locationName != null) {
      try {
        final IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
        final IWebBrowser browser = support.getExternalBrowser();

        final URL url = new URL("http://en.wikipedia.org/wiki/" + locationName);

        browser.openURL(url);
      } catch (MalformedURLException e) {
        Sapphire.service(LoggingService.class).log(e);
      } catch (PartInitException e) {
        Sapphire.service(LoggingService.class).log(e);
      }
    }

    return null;
  }
 public PropertyMetaModelServiceContext(final PropertyDef property) {
   super(ID_PROPERTY_METAMODEL, Sapphire.services(), property, null, null);
 }
  @Override
  public String browse(final Presentation context) {
    final Property property = property();

    final EnumSet<JavaTypeKind> kinds = EnumSet.noneOf(JavaTypeKind.class);

    if (this.paramKinds != null) {
      for (String kindString : this.paramKinds.split(",")) {
        kindString = kindString.trim();

        if (kindString.equalsIgnoreCase(JavaTypeKind.CLASS.name())) {
          kinds.add(JavaTypeKind.CLASS);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.ABSTRACT_CLASS.name())) {
          kinds.add(JavaTypeKind.ABSTRACT_CLASS);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.INTERFACE.name())) {
          kinds.add(JavaTypeKind.INTERFACE);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.ANNOTATION.name())) {
          kinds.add(JavaTypeKind.ANNOTATION);
        } else if (kindString.equalsIgnoreCase(JavaTypeKind.ENUM.name())) {
          kinds.add(JavaTypeKind.ENUM);
        } else {
          final String msg = typeKindNotRecognized.format(kindString);
          Sapphire.service(LoggingService.class).logError(msg);
        }
      }
    } else {
      final JavaTypeConstraintService javaTypeConstraintService =
          property.service(JavaTypeConstraintService.class);

      if (javaTypeConstraintService != null) {
        kinds.addAll(javaTypeConstraintService.kinds());
      }
    }

    int browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
    int count = kinds.size();

    if (count == 1) {
      final JavaTypeKind kind = kinds.iterator().next();

      switch (kind) {
        case CLASS:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES;
          break;
        case ABSTRACT_CLASS:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES;
          break;
        case INTERFACE:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_INTERFACES;
          break;
        case ANNOTATION:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES;
          break;
        case ENUM:
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ENUMS;
          break;
        default:
          throw new IllegalStateException();
      }
    } else if (count == 2) {
      if (kinds.contains(JavaTypeKind.CLASS) || kinds.contains(JavaTypeKind.ABSTRACT_CLASS)) {
        if (kinds.contains(JavaTypeKind.INTERFACE)) {
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES;
        } else if (kinds.contains(JavaTypeKind.ENUM)) {
          browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS;
        }
      }
    }

    final IProject project = property.element().adapt(IProject.class);

    try {
      final SelectionDialog dlg =
          JavaUI.createTypeDialog(
              ((FormComponentPresentation) context).shell(),
              null,
              project,
              browseDialogStyle,
              false);

      dlg.setTitle(
          dialogTitle.format(
              property.definition().getLabel(true, CapitalizationType.TITLE_STYLE, false)));

      if (dlg.open() == SelectionDialog.OK) {
        Object results[] = dlg.getResult();
        assert results != null && results.length == 1;
        if (results[0] instanceof IType) {
          return ((IType) results[0]).getFullyQualifiedName();
        }
      }
    } catch (JavaModelException e) {
      Sapphire.service(LoggingService.class).log(e);
    }

    return null;
  }