Package org.eclipse.jface.viewers

Examples of org.eclipse.jface.viewers.ISelection


                    return true;

                if (URLTransfer.getInstance().isSupportedType(transferType))
                    return true;

                ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
                if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                    return false;
                }

                Iterator< ? > iterator = ((IStructuredSelection) selection).iterator();
                while (iterator.hasNext()) {
                    Object element = iterator.next();
                    if (!(element instanceof RepositoryBundle) && !(element instanceof RepositoryBundleVersion) && !(element instanceof ProjectBundle)) {
                        return false;
                    }
                }
                return true;
            }

            @Override
            public boolean performDrop(Object data) {
                TransferData transfer = getCurrentEvent().currentDataType;

                if (URLTransfer.getInstance().isSupportedType(transfer)) {
                    String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
                    return handleURLDrop(urlStr);
                } else if (data instanceof String[]) {
                    return handleFileNameDrop((String[]) data);
                } else if (data instanceof IResource[]) {
                    return handleResourceDrop((IResource[]) data);
                } else {
                    return handleSelectionDrop();
                }
            }

            private boolean handleResourceDrop(IResource[] resources) {
                File[] files = new File[resources.length];
                for (int i = 0; i < resources.length; i++) {
                    files[i] = resources[i].getLocation().toFile();
                }
                return handleFileDrop(files);
            }

            private boolean handleFileNameDrop(String[] paths) {
                File[] files = new File[paths.length];
                for (int i = 0; i < paths.length; i++) {
                    files[i] = new File(paths[i]);
                }
                return handleFileDrop(files);
            }

            private boolean handleFileDrop(File[] files) {
                if (files.length > 0) {
                    BndPreferences prefs = new BndPreferences();
                    boolean hideWarning = prefs.getHideWarningExternalFile();
                    if (!hideWarning) {
                        MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files",
                                "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
                        if (Window.CANCEL == dialog.getReturnCode())
                            return false;
                        if (dialog.getToggleState()) {
                            prefs.setHideWarningExternalFile(true);
                        }
                    }

                    AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
                    WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                    if (Window.OK == dialog.open()) {
                        List<Pair<String,String>> addingBundles = wizard.getSelectedBundles();
                        List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());

                        for (Pair<String,String> addingBundle : addingBundles) {
                            Attrs attribs = new Attrs();
                            attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
                            addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
                        }

                        handleAdd(addingClauses);
                    }
                    return true;
                }
                return false;
            }

            private boolean handleSelectionDrop() {
                ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
                if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                    return false;
                }
                List<VersionedClause> adding = new LinkedList<VersionedClause>();
                Iterator< ? > iterator = ((IStructuredSelection) selection).iterator();
                while (iterator.hasNext()) {
View Full Code Here


        btnMoveDown.setEnabled(false);

        // LISTENERS
        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
                boolean enabled = selection != null && !selection.isEmpty();
                removeItem.setEnabled(enabled);
                btnMoveUp.setEnabled(enabled);
                btnMoveDown.setEnabled(enabled);
                getManagedForm().fireSelectionChanged(TestSuitesPart.this, selection);
            }
View Full Code Here

        });
        vwrActivateStub.setInput(EnumSet.allOf(ActivateSignature.class));
        vwrActivateStub.setSelection(new StructuredSelection(activateSignature), true);
        vwrActivateStub.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                ISelection sel = event.getSelection();
                if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
                    activateSignature = (ActivateSignature) ((IStructuredSelection) sel).getFirstElement();
                } else {
                    activateSignature = ActivateSignature.NoActivate;
                }
                activateSignatureStatus = activateSignatureChanged();
View Full Code Here

        });
        tableViewer.getTable().addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent event) {
                if (event.keyCode == SWT.F2 && event.stateMask == 0) {
                    ISelection selection = tableViewer.getSelection();
                    if (!(selection instanceof IStructuredSelection))
                        return;
                    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                    tableViewer.editElement(structuredSelection.getFirstElement(), 0);
                }
View Full Code Here

            }
        });

        viewerDirect.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                ISelection sel = event.getSelection();
                if (sel.isEmpty())
                    selection = (ResourceDescriptor) ((IStructuredSelection) viewerIndirect.getSelection()).getFirstElement();
                else
                    selection = (ResourceDescriptor) ((IStructuredSelection) sel).getFirstElement();
                getContainer().updateMessage();
            }
        });
        viewerIndirect.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                ISelection sel = event.getSelection();
                if (sel.isEmpty())
                    selection = (ResourceDescriptor) ((IStructuredSelection) viewerDirect.getSelection()).getFirstElement();
                else
                    selection = (ResourceDescriptor) ((IStructuredSelection) sel).getFirstElement();
                getContainer().updateMessage();
            }
View Full Code Here

  }
 
  @Override
  public SelectionData getSelectionRange() {
    ISelectionProvider sp = editor.getEditorSite().getSelectionProvider();
    ISelection selection = sp.getSelection();
     
    SelectionData result = new SelectionData();
   
    if (selection instanceof ITextSelection) {
      ITextSelection txSel = (ITextSelection) selection;
View Full Code Here

   */
  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
    this.part = targetPart;
    //IResourceNavigator nav = (IResourceNavigator) part;
   
    ISelection selection = part.getSite()
        .getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
      IStructuredSelection sel=(IStructuredSelection) selection;
      Object firstElement = sel.getFirstElement();
 
View Full Code Here

    private IFolder folder = null;

    public void setActivePart(IAction action, IWorkbenchPart targetPart)
    {
        this.part = targetPart;
        ISelection selection = part.getSite().getSelectionProvider()
            .getSelection();
        if (selection instanceof IStructuredSelection)
        {
            IStructuredSelection sel = (IStructuredSelection) selection;
            Object firstElement = sel.getFirstElement();
View Full Code Here

    viewer.setContentProvider(new URIsContentProvider());
    viewer.setInput(urls);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

      public void selectionChanged(SelectionChangedEvent event) {
        ISelection selection = event.getSelection();
        removeButton.setEnabled(!selection.isEmpty());
        editButton.setEnabled(!selection.isEmpty() && selection instanceof IStructuredSelection
            && ((IStructuredSelection) selection).toArray().length == 1);
      }
    });

    Composite buttonComposite = new Composite(composite, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).applyTo(buttonComposite);
    GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.FILL).applyTo(buttonComposite);

    addButton = new Button(buttonComposite, SWT.PUSH);
    addButton.setText(Messages.COMMONTXT_ADD);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false).applyTo(addButton);
    addButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        ApplicationURLWizard wizard = new ApplicationURLWizard(cloudServer, null);
        WizardDialog dialog = new WizardDialog(addButton.getShell(), wizard);
        if (dialog.open() == Dialog.OK) {
          String newURI = wizard.getUrl();
          urls.add(newURI);
          update();
        }
      }
    });

    editButton = new Button(buttonComposite, SWT.PUSH);
    editButton.setText(Messages.COMMONTXT_EDIT);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false).applyTo(editButton);
    editButton.setEnabled(false);
    editButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
        String url = (String) selection.getFirstElement();

        ApplicationURLWizard wizard = new ApplicationURLWizard(cloudServer, url);
        WizardDialog dialog = new WizardDialog(addButton.getShell(), wizard);
        if (dialog.open() == Dialog.OK) {
          String newURI = wizard.getUrl();
          urls.remove(url);
          urls.add(newURI);
          update();
        }
      }
    });

    removeButton = new Button(buttonComposite, SWT.PUSH);
    removeButton.setText(Messages.COMMONTXT_REMOVE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false).applyTo(addButton);
    removeButton.setEnabled(false);
    removeButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
        Object[] selectedURLs = selection.toArray();
        for (Object selectedURL : selectedURLs) {
          urls.remove(selectedURL);
          update();
        }
      }
View Full Code Here

    editButton.setText(Messages.COMMONTXT_EDIT);
    editButton.setEnabled(false);
    editButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        ISelection selection = viewer.getSelection();
        if (selection instanceof IStructuredSelection) {
          IStructuredSelection sSelection = (IStructuredSelection) selection;
          Object element = sSelection.getFirstElement();
          if (element instanceof CloudServerURL) {
            CloudServerURL cloudUrl = (CloudServerURL) element;

            if (cloudUrl.getUserDefined()) {
              cloudUrls.remove(cloudUrl);
              CloudServerURL newUrl = promptForCloudURL(serverTypeId, e.display.getActiveShell(),
                  cloudUrls, cloudUrl.getUrl(), cloudUrl.getName());
              if (newUrl != null) {

                if (cloudUrl.getUrl().equals(newUrl.getUrl()) || canUpdateUrl(cloudUrl, newUrl)) {
                  addURL(newUrl);
                }
                else {
                  addURL(cloudUrl);
                }
              }
              else {
                addURL(cloudUrl);
              }
            }
            else {
              CloudServerURL url = CloudUiUtil.getWildcardUrl(cloudUrl, cloudUrls, getShell());
              if (url != null) {
                addURL(url);
              }
            }
            viewer.refresh(true);
          }
        }
      }
    });

    final Button removeButton = new Button(buttonComposite, SWT.PUSH);
    GridDataFactory.fillDefaults().applyTo(removeButton);
    removeButton.setText(Messages.COMMONTXT_REMOVE);
    removeButton.setEnabled(false);
    removeButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        ISelection selection = viewer.getSelection();
        if (selection instanceof IStructuredSelection) {
          IStructuredSelection sSelection = (IStructuredSelection) selection;
          Object[] selectedItems = sSelection.toArray();
          for (Object selectedItem : selectedItems) {
            if (selectedItem instanceof CloudServerURL) {
              CloudServerURL cloudUrl = (CloudServerURL) selectedItem;
              removeCloudUrl(cloudUrl);
            }
          }
        }
        viewer.refresh(true);
      }

    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

      public void selectionChanged(SelectionChangedEvent event) {
        ISelection selection = event.getSelection();
        if (selection instanceof IStructuredSelection) {
          boolean editEnabled = true;
          boolean removeEnabled = true;

          IStructuredSelection sSelection = (IStructuredSelection) selection;
View Full Code Here

TOP

Related Classes of org.eclipse.jface.viewers.ISelection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.