@Override
  protected Object run(final Presentation context) {
    final FormComponentPresentation p = (FormComponentPresentation) context;
    final SapphirePart part = (SapphirePart) getPart();

    final Set<Property> properties = new LinkedHashSet<Property>();
    collectProperties(part, properties);

    for (Iterator<Property> itr = properties.iterator(); itr.hasNext(); ) {
      if (itr.next().empty()) {
        itr.remove();
      }
    }

    if (properties.isEmpty()) {
      MessageDialog.openInformation(p.shell(), dialogTitle.text(), nothingToDoMessage.text());
    } else {
      final Set<Property> selectedProperties = PromptDialog.open(p.shell(), properties);

      for (Property property : selectedProperties) {
        property.clear();
      }
    }

    return null;
  }
  @Override
  protected void facts(final SortedSet<String> facts) {
    final Value<?> value = context(Value.class);
    final String def = value.getDefaultText();

    if (def != null) {
      if (value.definition().hasAnnotation(SensitiveData.class)) {
        facts.add(statementForSensitive.text());
      } else {
        facts.add(statement.format(new ValueSnapshot(value.definition(), def)));
      }
    }
  }
  @Override
  protected void facts(final SortedSet<String> facts) {
    final ValueProperty property = context(ValueProperty.class);
    final NumericRange range = property.getAnnotation(NumericRange.class);
    final String min = range.min();
    final String max = range.max();

    if (min.length() > 0) {
      facts.add(minValueStatement.format(new ValueSnapshot(property, min)));
    }

    if (max.length() > 0) {
      facts.add(maxValueStatement.format(new ValueSnapshot(property, max)));
    }
  }
  @Override
  public void init(final Property property) {
    super.init(property);

    this.possibleTypesService = property.service(PossibleTypesService.class);

    this.possibleTypesServiceListener =
        new Listener() {
          @Override
          public void handle(final Event event) {
            try {
              initBindingMetadata();
            } catch (Exception e) {
              final String msg =
                  failure.format(
                      property.element().type().getSimpleName(), property.name(), e.getMessage());
              Sapphire.service(LoggingService.class).logError(msg);
            }
          }
        };

    this.possibleTypesService.attach(this.possibleTypesServiceListener);

    try {
      initBindingMetadata();
    } catch (Exception e) {
      final String msg =
          failure.format(
              property.element().type().getSimpleName(), property.name(), e.getMessage());
      throw new RuntimeException(msg, e);
    }
  }
  @Override
  protected Status compute() {
    if (!this.versionCompatibilityService.compatible() && !context(Property.class).empty()) {
      final String message;

      final Version version = this.versionCompatibilityService.version();
      final String versioned = this.versionCompatibilityService.versioned();

      if (version == null) {
        message = versionConstraintTargetNotFoundMessage.text();
      } else {
        message = notCompatibleWithVersionMessage.format(version.toString(), versioned);
      }

      return Status.createErrorStatus(message);
    }

    return Status.createOkStatus();
  }
  protected void initBindingMetadata() {
    final XmlListBinding annotation = property().definition().getAnnotation(XmlListBinding.class);
    final XmlNamespaceResolver xmlNamespaceResolver =
        ((XmlResource) property().element().resource()).getXmlNamespaceResolver();

    final SortedSet<ElementType> possible = this.possibleTypesService.types();
    this.modelElementTypes = possible.toArray(new ElementType[possible.size()]);

    if (annotation == null) {
      this.path = new XmlPath(property().name(), xmlNamespaceResolver);

      this.xmlElementNames = new QName[this.modelElementTypes.length];

      for (int i = 0; i < this.modelElementTypes.length; i++) {
        this.xmlElementNames[i] =
            createDefaultElementName(this.modelElementTypes[i], xmlNamespaceResolver);
      }
    } else {
      if (annotation.path().length() > 0) {
        this.path = new XmlPath(annotation.path(), xmlNamespaceResolver);
      }

      final XmlListBinding.Mapping[] mappings = annotation.mappings();
      this.xmlElementNames = new QName[this.modelElementTypes.length];

      for (int i = 0; i < this.modelElementTypes.length; i++) {
        final ElementType type = this.modelElementTypes[i];

        for (XmlListBinding.Mapping mapping : mappings) {
          if (mapping.type() == type.getModelElementClass()) {
            final String mappingElementName = mapping.element().trim();

            if (mappingElementName.length() == 0) {
              throw new RuntimeException(mustSpecifyElementNameMsg.text());
            }

            this.xmlElementNames[i] = createQualifiedName(mappingElementName, xmlNamespaceResolver);

            break;
          }
        }

        if (this.xmlElementNames[i] == null) {
          this.xmlElementNames[i] = createDefaultElementName(type, xmlNamespaceResolver);
        }
      }
    }
  }
 static {
   LocalizableText.init(RestoreDefaultsActionHandler.class);
 }
    @Override
    protected Control createDialogArea(final Composite parent) {
      getShell().setText(dialogTitle.text());

      final Composite composite = (Composite) super.createDialogArea(parent);

      final Label messageLabel = new Label(composite, SWT.WRAP);
      messageLabel.setText(dialogMessage.text());
      messageLabel.setLayoutData(gdwhint(gdhfill(), 300));

      final CheckboxTableViewer tableViewer =
          CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
      final Table table = tableViewer.getTable();

      table.setLayoutData(gdhhint(gdwhint(gdfill(), 300), 300));

      tableViewer.setContentProvider(
          new IStructuredContentProvider() {
            public Object[] getElements(final Object inputElement) {
              return PromptDialog.this.allProperties.toArray();
            }

            public void inputChanged(
                final Viewer viewer, final Object oldInput, final Object newInput) {}

            public void dispose() {}
          });

      tableViewer.setLabelProvider(
          new ITableLabelProvider() {
            public String getColumnText(final Object element, final int columnIndex) {
              final PropertyDef property = ((Property) element).definition();
              return property.getLabel(true, CapitalizationType.FIRST_WORD_ONLY, false);
            }

            public Image getColumnImage(final Object element, final int columnIndex) {
              return null;
            }

            public boolean isLabelProperty(final Object element, final String property) {
              return false;
            }

            public void addListener(final ILabelProviderListener listener) {}

            public void removeListener(final ILabelProviderListener listener) {}

            public void dispose() {}
          });

      tableViewer.setCheckStateProvider(
          new ICheckStateProvider() {
            public boolean isChecked(final Object element) {
              return PromptDialog.this.selectedProperties.contains(element);
            }

            public boolean isGrayed(final Object element) {
              return false;
            }
          });

      tableViewer.addCheckStateListener(
          new ICheckStateListener() {
            public void checkStateChanged(final CheckStateChangedEvent event) {
              final Property property = (Property) event.getElement();

              if (event.getChecked() == true) {
                PromptDialog.this.selectedProperties.add(property);
              } else {
                PromptDialog.this.selectedProperties.remove(property);
              }
            }
          });

      tableViewer.setInput(this);

      return composite;
    }
 static {
   LocalizableText.init(VersionCompatibilityValidationService.class);
 }
Пример #10
0
  protected final Status validateExtensions(final Path path) {
    if (this.fileExtensionsService != null) {
      final String fileName = path.lastSegment();

      if (fileName != null) {
        final List<String> extensions = this.fileExtensionsService.extensions();
        final int count = (extensions == null ? 0 : extensions.size());

        if (count > 0) {
          final String trimmedFileName = fileName.trim();
          final int lastdot = trimmedFileName.lastIndexOf('.');
          final String extension;

          if (lastdot == -1) {
            extension = "";
          } else {
            extension = trimmedFileName.substring(lastdot + 1);
          }

          boolean match = false;

          if (extension != null && extension.length() != 0) {
            for (String ext : extensions) {
              if (extension.equalsIgnoreCase(ext)) {
                match = true;
                break;
              }
            }
          }

          if (!match) {
            final String message;

            if (count == 1) {
              message = invalidFileExtensionOne.format(trimmedFileName, extensions.get(0));
            } else if (count == 2) {
              message =
                  invalidFileExtensionTwo.format(
                      trimmedFileName, extensions.get(0), extensions.get(1));
            } else {
              final StringBuilder buf = new StringBuilder();

              for (String ext : extensions) {
                if (buf.length() != 0) {
                  buf.append(", ");
                }

                buf.append(ext);
              }

              message = invalidFileExtensionMultiple.format(trimmedFileName, buf.toString());
            }

            return Status.createErrorStatus(message);
          }
        }
      }
    }

    return Status.createOkStatus();
  }
  @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;
  }
Пример #12
0
 @Override
 public String getMessage() {
   return cycleDetectedMessage.format(convertToString(this.cycle));
 }
 static {
   LocalizableText.init(StandardXmlListBindingImpl.class);
 }
 static {
   LocalizableText.init(NumericRangeFactsService.class);
 }
Пример #15
0
 static {
   LocalizableText.init(DefaultValueFactsService.class);
 }
Пример #16
0
 @Override
 public void handleCycle(final List<Entity> cycle) {
   this.stream.println(cycleDetectedMessage.format(convertToString(cycle)));
 }
Пример #17
0
 static {
   LocalizableText.init(PathValidationService.class);
 }
Пример #18
0
 static {
   LocalizableText.init(TopologicalSorter.class);
 }
 static {
   LocalizableText.init(JavaTypeBrowseActionHandler.class);
 }