コード例 #1
0
 private void handleImportEnabledChanged() {
   if (project.isImportsEnabled() && !enableImportText.getSelection()) {
     hasUserMadeChanges = true;
     project.setImportsEnabled(enableImportText.getSelection());
   } else if (!project.isImportsEnabled() && enableImportText.getSelection()) {
     hasUserMadeChanges = true;
     project.setImportsEnabled(enableImportText.getSelection());
   }
 }
コード例 #2
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();
 }
コード例 #3
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;
      }
    }
  }
コード例 #4
0
 /** The user has pressed the remove button. Delete the selected configuration. */
 private void handleRemoveButtonPressed() {
   IStructuredSelection selection = (IStructuredSelection) configsViewer.getSelection();
   if (!selection.isEmpty()) {
     Iterator elements = selection.iterator();
     while (elements.hasNext()) {
       IBeansConfig config = (IBeansConfig) elements.next();
       project.removeConfig(config.getElementName());
     }
     configsViewer.refresh(false);
     hasUserMadeChanges = true;
   }
 }
コード例 #5
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;
     }
   }
 }
コード例 #6
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;
  }