Exemplo n.º 1
0
 /**
  * The user has modified the comma-separated list of config suffixes. Validate the input and
  * update the "Add" button enablement and error label accordingly.
  */
 private void handleSuffixesTextModified() {
   String errorMessage = null;
   Set<String> suffixes = new LinkedHashSet<String>();
   String extText = suffixesText.getText().trim();
   if (extText.length() == 0) {
     errorMessage = BeansUIPlugin.getResourceString(ERROR_NO_SUFFIXES);
   } else {
     StringTokenizer tokenizer = new StringTokenizer(extText, ",");
     while (tokenizer.hasMoreTokens()) {
       String suffix = tokenizer.nextToken().trim();
       if (isValidSuffix(suffix)) {
         suffixes.add(suffix);
       } else {
         errorMessage = BeansUIPlugin.getResourceString(ERROR_INVALID_SUFFIXES);
         break;
       }
     }
     if (errorMessage == null) {
       project.setConfigSuffixes(suffixes);
       hasUserMadeChanges = true;
     }
   }
   if (errorMessage != null) {
     errorLabel.setText(errorMessage);
     addButton.setEnabled(false);
   } else {
     errorLabel.setText("");
     addButton.setEnabled(true);
   }
   errorLabel.getParent().update();
 }
Exemplo n.º 2
0
 /** Returns an {@link Image} instance which is located at the indicated icon path. */
 private static Image getImage(String ns, String icon) {
   if (StringUtils.hasText(icon)) {
     synchronized (IMAGE_REGISTRY_LOCK) {
       Image image = BeansUIPlugin.getDefault().getImageRegistry().get(icon);
       if (image == null) {
         ImageDescriptor imageDescriptor = BeansUIPlugin.imageDescriptorFromPlugin(ns, icon);
         BeansUIPlugin.getDefault().getImageRegistry().put(icon, imageDescriptor);
         image = BeansUIPlugin.getDefault().getImageRegistry().get(icon);
       }
       return image;
     }
   } else {
     return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD);
   }
 }
Exemplo n.º 3
0
 /**
  * Returns the {@link INamespaceLabelProvider} for the given {@link ISourceModelElement}'s
  * namespace.
  */
 public static INamespaceLabelProvider getLabelProvider(ISourceModelElement element) {
   IExtensionPoint point =
       Platform.getExtensionRegistry().getExtensionPoint(NAMESPACES_EXTENSION_POINT);
   if (point != null) {
     String namespaceURI = getNameSpaceURI(element);
     for (IExtension extension : point.getExtensions()) {
       for (IConfigurationElement config : extension.getConfigurationElements()) {
         if (namespaceURI.equals(config.getAttribute("uri"))) {
           if (config.getAttribute("labelProvider") != null) {
             try {
               Object provider = config.createExecutableExtension("labelProvider");
               if (provider instanceof INamespaceLabelProvider) {
                 return (INamespaceLabelProvider) provider;
               }
             } catch (CoreException e) {
               BeansUIPlugin.log(e);
             }
           }
           return null;
         }
       }
     }
   }
   return null;
 }
Exemplo n.º 4
0
  protected void handleScanButtonPressed() {
    ScannedFilesContentProvider contentProvider =
        new ScannedFilesContentProvider(suffixesText.getText());
    CheckedTreeSelectionDialog dialog =
        new CheckedTreeSelectionDialog(
            SpringUIUtils.getStandardDisplay().getActiveShell(),
            new ScannedFilesLabelProvider(),
            contentProvider) {

          @Override
          protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);
            Label note = new Label(composite, SWT.WRAP);
            note.setText(BeansUIPlugin.getResourceString(SCAN_NOTE_LABEL));
            note.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
            return composite;
          }
        };
    dialog.setTitle(BeansUIPlugin.getResourceString(DIALOG_TITLE));
    dialog.setMessage(BeansUIPlugin.getResourceString(DIALOG_MESSAGE));
    dialog.addFilter(new ConfigFileFilter(project.getConfigSuffixes()));
    dialog.setValidator(new StorageSelectionValidator(true));
    dialog.setInput(project.getProject());
    dialog.setSorter(new JavaElementSorter());
    dialog.setInitialSelections(contentProvider.getElements(project.getProject()));

    if (dialog.open() == Window.OK) {
      Object[] selection = dialog.getResult();
      if (selection != null && selection.length > 0) {
        for (Object element : selection) {
          String config;
          if (element instanceof ZipEntryStorage) {
            ZipEntryStorage storage = (ZipEntryStorage) element;
            config = storage.getFullName();
          } else {
            IFile file = (IFile) element;
            config = file.getProjectRelativePath().toString();
          }
          project.addConfig(config, IBeansConfig.Type.MANUAL);
        }
        configsViewer.refresh(false);
        hasUserMadeChanges = true;
      }
    }
  }
Exemplo n.º 5
0
 /** Returns an {@link Image} instance which is located at the indicated icon path. */
 public static Image getImage(
     org.springframework.ide.eclipse.beans.core.model.INamespaceDefinition namespaceDefinition) {
   if (StringUtils.hasText(namespaceDefinition.getIconPath())) {
     synchronized (IMAGE_REGISTRY_LOCK) {
       Image image =
           BeansUIPlugin.getDefault().getImageRegistry().get(namespaceDefinition.getIconPath());
       if (image == null) {
         InputStream is = namespaceDefinition.getIconStream();
         if (is != null) {
           try {
             ImageDescriptor imageDescriptor =
                 ImageDescriptor.createFromImageData(new ImageData(is));
             BeansUIPlugin.getDefault()
                 .getImageRegistry()
                 .put(namespaceDefinition.getIconPath(), imageDescriptor);
             image =
                 BeansUIPlugin.getDefault()
                     .getImageRegistry()
                     .get(namespaceDefinition.getIconPath());
           } catch (Exception e) {
             BeansUIPlugin.log(
                 String.format(
                     "Error creating image resource for namespace definition '%s'",
                     namespaceDefinition.getNamespaceUri()),
                 e);
             return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD);
           } finally {
             if (is != null) {
               try {
                 is.close();
               } catch (IOException e) {
               }
             }
           }
         } else {
           BeansUIPlugin.getDefault()
               .getImageRegistry()
               .put(
                   namespaceDefinition.getIconPath(),
                   BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD));
           image =
               BeansUIPlugin.getDefault()
                   .getImageRegistry()
                   .get(namespaceDefinition.getIconPath());
         }
       }
       return image;
     }
   } else {
     return BeansUIImages.getImage(BeansUIImages.IMG_OBJS_XSD);
   }
 }
Exemplo n.º 6
0
 /**
  * The user has pressed the add button. Opens the configuration selection dialog and adds the
  * selected configuration.
  */
 private void handleAddButtonPressed() {
   SelectionStatusDialog dialog;
   if (SpringCoreUtils.isEclipseSameOrNewer(3, 2)) {
     FilteredElementTreeSelectionDialog selDialog =
         new FilteredElementTreeSelectionDialog(
             SpringUIUtils.getStandardDisplay().getActiveShell(),
             new LabelProvider(),
             new NonJavaResourceContentProvider());
     selDialog.addFilter(new ConfigFileFilter(project.getConfigSuffixes()));
     selDialog.setValidator(new StorageSelectionValidator(true));
     selDialog.setInput(project.getProject());
     selDialog.setSorter(new JavaElementSorter());
     dialog = selDialog;
   } else {
     ElementTreeSelectionDialog selDialog =
         new ElementTreeSelectionDialog(
             SpringUIUtils.getStandardDisplay().getActiveShell(),
             new LabelProvider(),
             new NonJavaResourceContentProvider());
     selDialog.addFilter(new ConfigFileFilter(project.getConfigSuffixes()));
     selDialog.setValidator(new StorageSelectionValidator(true));
     selDialog.setInput(project.getProject());
     selDialog.setSorter(new JavaElementSorter());
     dialog = selDialog;
   }
   dialog.setTitle(BeansUIPlugin.getResourceString(DIALOG_TITLE));
   dialog.setMessage(BeansUIPlugin.getResourceString(DIALOG_MESSAGE));
   if (dialog.open() == Window.OK) {
     Object[] selection = dialog.getResult();
     if (selection != null && selection.length > 0) {
       for (Object element : selection) {
         String config = null;
         if (element instanceof ZipEntryStorage) {
           ZipEntryStorage storage = (ZipEntryStorage) element;
           config = storage.getFullName();
         } else if (element instanceof IFile) {
           IFile file = (IFile) element;
           config = file.getProjectRelativePath().toString();
         } else if (element instanceof JarEntryFile) {
           IPath fullPath =
               ((JarPackageFragmentRoot) ((JarEntryFile) element).getPackageFragmentRoot())
                   .getPath();
           String entryName = ((JarEntryFile) element).getFullPath().toString();
           for (String name : JavaCore.getClasspathVariableNames()) {
             IPath variablePath = JavaCore.getClasspathVariable(name);
             if (variablePath != null && variablePath.isPrefixOf(fullPath)) {
               if (MessageDialog.openQuestion(
                   SpringUIUtils.getStandardDisplay().getActiveShell(),
                   "Use classpath variable",
                   "Do you want to use the classpath variable '"
                       + name
                       + "' to refer to the config file\n'"
                       + entryName
                       + "'?")) {
                 fullPath =
                     new Path(name)
                         .append(fullPath.removeFirstSegments(variablePath.segmentCount()));
               }
               break;
             }
           }
           config =
               IBeansConfig.EXTERNAL_FILE_NAME_PREFIX
                   + fullPath.toString()
                   + ZipEntryStorage.DELIMITER
                   + entryName;
         }
         if (config != null) {
           project.addConfig(config, IBeansConfig.Type.MANUAL);
         }
       }
       configsViewer.refresh(false);
       hasUserMadeChanges = true;
     }
   }
 }
Exemplo n.º 7
0
  public Control createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 3;
    layout.marginWidth = 3;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label description = new Label(composite, SWT.WRAP);
    description.setText(BeansUIPlugin.getResourceString(DESCRIPTION));
    description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Composite tableAndButtons = new Composite(composite, SWT.NONE);
    tableAndButtons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    tableAndButtons.setLayout(layout);

    // Create table and viewer for Spring bean config files
    configsTable =
        new Table(
            tableAndButtons,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = TABLE_WIDTH;
    data.heightHint = TABLE_WIDTH;
    configsTable.setLayoutData(data);
    configsTable.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleTableSelectionChanged();
          }
        });
    configsViewer = new TableViewer(configsTable);
    configsViewer.setContentProvider(new ConfigFilesContentProvider(project));
    configsViewer.setLabelProvider(new PropertiesModelLabelProvider());
    configsViewer.setInput(this); // activate content provider
    configsViewer.setSorter(new ConfigFilesSorter());

    if (this.selectedElement != null) {
      configsViewer.setSelection(new StructuredSelection(selectedElement), true);
    }

    if (BeansConfigLocatorFactory.hasEnabledBeansConfigLocatorDefinitions(project.getProject())) {
      Label note = new Label(composite, SWT.WRAP);
      note.setText(BeansUIPlugin.getResourceString(NOTE_LABEL));
      note.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }

    Label options = new Label(composite, SWT.WRAP);
    options.setText("Options:");
    options.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create enable import checkbox
    enableImportText =
        SpringUIUtils.createCheckBox(
            composite, BeansUIPlugin.getResourceString(ENABLE_IMPORT_LABEL));
    enableImportText.setSelection(project.isImportsEnabled());
    enableImportText.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleImportEnabledChanged();
          }
        });

    // Create ignore missing namespace handler checkbox
    ignoreMissingNamespaceHandlerText =
        SpringUIUtils.createCheckBox(
            composite, BeansUIPlugin.getResourceString(IGNORE_MISSING_NAMESPACEHANDLER_LABEL));
    ignoreMissingNamespaceHandlerText.setSelection(
        SpringCorePreferences.getProjectPreferences(project.getProject(), BeansCorePlugin.PLUGIN_ID)
            .getBoolean(
                BeansCorePlugin.IGNORE_MISSING_NAMESPACEHANDLER_PROPERTY,
                BeansCorePlugin.IGNORE_MISSING_NAMESPACEHANDLER_PROPERTY_DEFAULT));
    ignoreMissingNamespaceHandlerText.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            hasUserMadeChanges = true;
          }
        });

    // Create suffix text field
    suffixesText =
        SpringUIUtils.createTextField(composite, BeansUIPlugin.getResourceString(SUFFIXES_LABEL));
    suffixesText.setText(StringUtils.collectionToDelimitedString(project.getConfigSuffixes(), ","));
    suffixesText.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            handleSuffixesTextModified();
          }
        });

    // Create error label
    errorLabel = new Label(composite, SWT.NONE);
    errorLabel.setLayoutData(
        new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    errorLabel.setForeground(JFaceColors.getErrorText(parent.getDisplay()));
    errorLabel.setBackground(JFaceColors.getErrorBackground(parent.getDisplay()));
    // Create button area
    Composite buttonArea = new Composite(tableAndButtons, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttonArea.setLayout(layout);
    buttonArea.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    addButton =
        SpringUIUtils.createButton(
            buttonArea, BeansUIPlugin.getResourceString(ADD_BUTTON), buttonListener);
    removeButton =
        SpringUIUtils.createButton(
            buttonArea, BeansUIPlugin.getResourceString(REMOVE_BUTTON), buttonListener, 0, false);
    scanButton = SpringUIUtils.createButton(buttonArea, "Scan...", buttonListener);
    model.addChangeListener(modelChangeListener);
    handleSuffixesTextModified();
    hasUserMadeChanges = false;
    // handleSuffixTextModified() has set this to true

    handleTableSelectionChanged();
    return composite;
  }