public DNDExampleTab() {
   super("Drag & Drop");
   dragEnabled = true;
   dropEnabled = true;
   addDragTransfer(TextTransfer.getInstance());
   addDropTransfer(TextTransfer.getInstance());
 }
  private void installTitleDrag(Form form) {
    if (titleDragSourceListener == null /*&& !hasLeftToolBar()*/) {
      Transfer[] transferTypes;
      if (null == task) {
        transferTypes = new Transfer[] {TextTransfer.getInstance()};
      } else {
        transferTypes =
            new Transfer[] {
              LocalSelectionTransfer.getTransfer(),
              TextTransfer.getInstance(),
              FileTransfer.getInstance()
            };
      }
      titleDragSourceListener =
          new TaskDragSourceListener(
              new SelectionProviderAdapter() {
                @Override
                public ISelection getSelection() {
                  return new StructuredSelection(task);
                }
              });

      if (titleLabel != null) {
        DragSource source = new DragSource(titleLabel, DND.DROP_MOVE | DND.DROP_LINK);
        source.setTransfer(transferTypes);
        source.addDragListener(titleDragSourceListener);
      } else {
        form.addTitleDragSupport(
            DND.DROP_MOVE | DND.DROP_LINK, transferTypes, titleDragSourceListener);
      }
    }
  }
  private void doCutCopyWithImportsOperation() {
    ITextEditor editor = getTextEditor();
    ITypeRoot inputElement = JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
    ISelection selection = editor.getSelectionProvider().getSelection();

    Object clipboardData = null;
    if (inputElement != null && selection instanceof ITextSelection && !selection.isEmpty()) {
      ITextSelection textSelection = (ITextSelection) selection;
      if (isNonTrivialSelection(textSelection)) {
        clipboardData =
            getClipboardData(inputElement, textSelection.getOffset(), textSelection.getLength());
      }
    }

    fOperationTarget.doOperation(fOperationCode);

    if (clipboardData != null) {
      /*
       * We currently make assumptions about what the styled text widget sets,
       * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=61876
       */
      Clipboard clipboard = new Clipboard(getDisplay());
      try {
        Object textData = clipboard.getContents(TextTransfer.getInstance());
        /*
         * Don't add if we didn't get any text data from the clipboard, see:
         * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=70077
         * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=200743
         */
        if (textData == null) return;

        ArrayList<Object> datas = new ArrayList<Object>(3);
        ArrayList<ByteArrayTransfer> transfers = new ArrayList<ByteArrayTransfer>(3);
        datas.add(textData);
        transfers.add(TextTransfer.getInstance());

        Object rtfData = clipboard.getContents(RTFTransfer.getInstance());
        if (rtfData != null) {
          datas.add(rtfData);
          transfers.add(RTFTransfer.getInstance());
        }

        datas.add(clipboardData);
        transfers.add(fgTransferInstance);

        Transfer[] dataTypes = transfers.toArray(new Transfer[transfers.size()]);
        Object[] data = datas.toArray();
        setClipboardContents(clipboard, data, dataTypes);
      } finally {
        clipboard.dispose();
      }
    }
  }
Exemple #4
0
  /**
   * Return a native data type that represents the dropped object
   *
   * <pre>
   *    URLTransfer             URI
   *    FileTransfer            File[]
   *    TextTransfer            String
   *    ImageTransfer           ImageData
   * </pre>
   *
   * @param data the dropped object
   * @return a native data type that represents the dropped object, or null when the data type is
   *     unknown
   * @throws Exception upon error
   */
  Object toJava(TransferData data) throws Exception {
    if (URLTransfer.getInstance().isSupportedType(data))
      return Converter.cnv(URI.class, URLTransfer.getInstance().nativeToJava(data));
    else if (FileTransfer.getInstance().isSupportedType(data)) {
      return Converter.cnv(File[].class, FileTransfer.getInstance().nativeToJava(data));
    } else if (TextTransfer.getInstance().isSupportedType(data)) {
      return TextTransfer.getInstance().nativeToJava(data);
    }
    // Need to write the transfer code since the ImageTransfer turns it into
    // something very Eclipsy
    //        else if (ImageTransfer.getInstance().isSupportedType(data))
    //            return ImageTransfer.getInstance().nativeToJava(data);

    return null;
  }
  public void performVisibleTableDragOver(DropTargetEvent event) {
    if (!TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
      event.detail = DND.DROP_NONE;
      return;
    }

    Tree tree = visibleColTable.getViewer().getTree();
    TreeItem dragOverTreeItem =
        tree.getItem(visibleColTable.getViewer().getTree().toControl(event.x, event.y));
    if (dragOverTreeItem == null) {
      return;
    }

    event.feedback = DND.FEEDBACK_EXPAND;
    event.detail = DND.DROP_NONE;

    IStructuredSelection selectedItem =
        (IStructuredSelection) visibleColTable.getViewer().getSelection();
    if (selectedItem == null || selectedItem.isEmpty()) {
      selectedItem = (IStructuredSelection) hiddenColTable.getViewer().getSelection();
    }
    if (selectedItem == null) {
      return;
    }
    Object obj = selectedItem.getFirstElement();
    if (obj instanceof XViewerColumn) {
      if (isFeedbackAfter) {
        event.feedback = DND.FEEDBACK_INSERT_AFTER;
      } else {
        event.feedback = DND.FEEDBACK_INSERT_BEFORE;
      }
      event.detail = DND.DROP_MOVE;
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.ViewerDropAdapter#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
   */
  public void dragEnter(DropTargetEvent event) {
    fDropType = DROP_TYPE_DEFAULT;
    event.detail = DND.DROP_NONE;

    for (int i = 0; i < event.dataTypes.length; i++) {
      if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataTypes[i])) {
        if (isExpressionDrop()) {
          event.currentDataType = event.dataTypes[i];
          event.detail = DND.DROP_MOVE;
          fDropType = DROP_TYPE_EXPRESSION;
          break;
        } else if (isVariableDrop()) {
          event.currentDataType = event.dataTypes[i];
          event.detail = DND.DROP_COPY;
          fDropType = DROP_TYPE_VARIABLE;
          break;
        } else if (isWatchAdaptableElementDrop()) {
          event.currentDataType = event.dataTypes[i];
          event.detail = DND.DROP_COPY;
          fDropType = DROP_TYPE_WATCH_ADAPTABLE_ELEMENT;
          break;
        }
      } else if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
        event.currentDataType = event.dataTypes[i];
        event.detail = DND.DROP_COPY;
        fDropType = DROP_TYPE_DEFAULT;
        break;
      }
    }

    super.dragEnter(event);
  }
Exemple #7
0
 /**
  * Return the class of the dropped object
  *
  * <pre>
  *    URLTransfer             URI
  *    FileTransfer            File[]
  *    TextTransfer            String
  *    ImageTransfer           ImageData
  * </pre>
  *
  * @param data the dropped object
  * @return the class of the dropped object, or null when it's unknown
  * @throws Exception upon error
  */
 Class<?> toJavaType(TransferData data) throws Exception {
   if (URLTransfer.getInstance().isSupportedType(data)) return URI.class;
   if (FileTransfer.getInstance().isSupportedType(data)) return File[].class;
   if (TextTransfer.getInstance().isSupportedType(data)) return String.class;
   //        if (ImageTransfer.getInstance().isSupportedType(data))
   //            return Image.class;
   return null;
 }
  private void createVisibleButtonsComposition(Composite parent) {
    final Composite visibleTableComp = new Composite(parent, SWT.NONE);
    visibleTableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final GridLayout gridLayout_6 = new GridLayout();
    gridLayout_6.marginWidth = 0;
    gridLayout_6.marginHeight = 0;
    visibleTableComp.setLayout(gridLayout_6);

    final Label visibleColumnsLabel = new Label(visibleTableComp, SWT.NONE);
    visibleColumnsLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    visibleColumnsLabel.setText("Visible Columns");

    // Visible Column Table
    visibleColTable = new XViewerFilteredTree(visibleTableComp);
    final Tree table = visibleColTable.getViewer().getTree();
    final GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_table.widthHint = 300;
    table.setLayoutData(gd_table);
    visibleColTable.getViewer().setLabelProvider(new XViewerColumnLabelProvider());
    visibleColTable.getViewer().setContentProvider(new ArrayTreeContentProvider());
    visibleColTable
        .getViewer()
        .addSelectionChangedListener(
            new ISelectionChangedListener() {
              @Override
              public void selectionChanged(SelectionChangedEvent event) {
                updateButtonEnablements();
              }
            });
    visibleColTable
        .getViewer()
        .addDragSupport(
            DND.DROP_MOVE, new Transfer[] {TextTransfer.getInstance()}, visibleTableDragListener);
    visibleColTable
        .getViewer()
        .addDropSupport(
            DND.DROP_MOVE, new Transfer[] {TextTransfer.getInstance()}, visibleTableDropListener);
    hiddenColTable
        .getViewer()
        .addDragSupport(
            DND.DROP_MOVE, new Transfer[] {TextTransfer.getInstance()}, hiddenTableDragListener);
    hiddenColTable
        .getViewer()
        .addDropSupport(
            DND.DROP_MOVE, new Transfer[] {TextTransfer.getInstance()}, hiddenTableDropListener);
  }
 /** Copy selected key to clipboard */
 private void copyToClipboard() {
   String key = getSelectedKey();
   if (key != null) {
     Clipboard clipboard = new Clipboard(getViewSite().getShell().getDisplay());
     clipboard.setContents(new Object[] {key}, new Transfer[] {TextTransfer.getInstance()});
     clipboard.dispose();
   }
 }
 /** Copies the table's contents to the clipboard. */
 public void copy() {
   if (tree != null && getItemCount(tree) > 0) {
     Clipboard clipboard = new Clipboard(tree.getTree().getDisplay());
     TextTransfer textTransfer = TextTransfer.getInstance();
     clipboard.setContents(new String[] {getText(tree)}, new Transfer[] {textTransfer});
     clipboard.dispose();
   }
 }
  public void createDragSourceComposite(Composite parent, IReferenceNodeInfo referenceNodeInfo) {
    // Composite c = new Composite(parent, SWT.BORDER);
    Group c = new Group(parent, SWT.SHADOW_ETCHED_IN);
    GridLayout gl = new GridLayout(2, false);
    gl.marginTop = 1;
    gl.marginBottom = 5;
    gl.marginLeft = 1;
    gl.marginRight = 1;
    gl.marginHeight = 1;
    gl.marginWidth = 1;
    gl.verticalSpacing = 0;
    gl.horizontalSpacing = 0;

    c.setLayout(gl);

    c.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    Label il = new Label(c, SWT.LEFT | SWT.NO_FOCUS);
    il.setImage(resources.getPlatformImage(ISharedImages.IMG_OBJS_INFO_TSK));
    il.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    Label l = new Label(c, SWT.LEFT | SWT.NO_FOCUS);
    l.setText("Drag this area to a target in the tree to quick-link.");
    l.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    c.pack();

    DragSource[] sources =
        new DragSource[] {
          // new DragSource(il, DND.DROP_MOVE | DND.DROP_COPY),
          new DragSource(l, DND.DROP_MOVE | DND.DROP_COPY),
          new DragSource(c, DND.DROP_MOVE | DND.DROP_COPY),
        };

    final ObjRef fParentRef = referenceNodeInfo.getParentRef();
    final String fFeatureName = referenceNodeInfo.getFeatureName();

    for (DragSource source : sources) {
      Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
      source.setTransfer(types);
      source.addDragListener(
          new DragSourceListener() {
            @Override
            public void dragStart(DragSourceEvent event) {
              event.doit = true;
            }

            @Override
            public void dragSetData(DragSourceEvent event) {
              if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
                event.data = "$LINK$" + fFeatureName + "$" + xarch.getXPath(fParentRef);
              }
            }

            @Override
            public void dragFinished(DragSourceEvent event) {
              if (event.detail == DND.DROP_MOVE) {}
            }
          });
    }
  }
  public void run(IAction action) {
    FastStringBuffer buf = new FastStringBuffer();
    try {
      PyEdit pyEdit = getPyEdit();

      PySelection pySelection = new PySelection(pyEdit);

      IPythonNature nature = pyEdit.getPythonNature();
      File editorFile = pyEdit.getEditorFile();

      if (editorFile != null) {
        if (nature != null) {
          String mod = nature.resolveModule(editorFile);
          if (mod != null) {
            buf.append(mod);

          } else {
            // Support for external files (not in PYTHONPATH).
            buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
          }
        } else {
          buf.append(FullRepIterable.getFirstPart(editorFile.getName()));
        }
      }

      List<stmtType> path =
          FastParser.parseToKnowGloballyAccessiblePath(
              pySelection.getDoc(), pySelection.getStartLineIndex());
      for (stmtType stmtType : path) {
        if (buf.length() > 0) {
          buf.append('.');
        }
        buf.append(NodeUtils.getRepresentationString(stmtType));
      }

    } catch (MisconfigurationException e1) {
      Log.log(e1);
      return;
    }

    Transfer[] dataTypes = new Transfer[] {TextTransfer.getInstance()};
    Object[] data = new Object[] {buf.toString()};

    Clipboard clipboard = new Clipboard(EditorUtils.getShell().getDisplay());
    try {
      clipboard.setContents(data, dataTypes);
    } catch (SWTError e) {
      if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) {
        throw e;
      }
      MessageDialog.openError(
          EditorUtils.getShell(), "Error copying to clipboard.", e.getMessage());
    } finally {
      clipboard.dispose();
    }
  }
 @Override
 public Transfer[] getSupportedTransferTypes() {
   return new Transfer[] {
     TextTransfer.getInstance(),
     FileTransfer.getInstance(),
     ResourceTransfer.getInstance(),
     EditorInputTransfer.getInstance(),
     LocalSelectionTransfer.getTransfer()
   };
 }
 public boolean canPaste(Clipboard clipboard) {
   TransferData[] types = clipboard.getAvailableTypes();
   Transfer[] transfers = new Transfer[] {TextTransfer.getInstance(), RTFTransfer.getInstance()};
   for (int i = 0; i < types.length; i++) {
     for (int j = 0; j < transfers.length; j++) {
       if (transfers[j].isSupportedType(types[i])) return true;
     }
   }
   return false;
 }
    /** @see Transfer#javaToNative */
    public void javaToNative(Object object, TransferData transferData) {
      String stringToEncode;

      Feature feature = (Feature) object;

      WKTWriter writer = new WKTWriter();
      String geometry = writer.writeFormatted(feature.getDefaultGeometry());

      stringToEncode = geometry;
      TextTransfer.getInstance().javaToNative(stringToEncode, transferData);
    }
  /** Drag should only be from visible table */
  public void performHiddenTableDragOver(DropTargetEvent event) {
    if (!TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
      event.detail = DND.DROP_NONE;
      return;
    }
    // Only allow drag from visibleColTable
    if (event.widget != visibleColTable) {
      return;
    }

    event.detail = DND.DROP_MOVE;
  }
  /**
   * Versucht eine SEPA-Ueberweisung aus der Zwischenablage zu erstellen.
   *
   * @return die Ueberweisung, wenn eine erstellt werden konnte oder null.
   */
  public AuslandsUeberweisung getUeberweisung() {
    try {
      // BUGZILLA 336
      final Clipboard cb = new Clipboard(GUI.getDisplay());
      TextTransfer transfer = TextTransfer.getInstance();
      String text = (String) cb.getContents(transfer);

      if (text == null || text.length() == 0) return null;

      text = text.trim();

      // Fuer den Fall, dass wir Key+Value nicht nur durch Doppelpunkt sondern zusaetzlich
      // auch noch durch einen Zeilenumbruch getrennt sind, entfernen wir Zeilen-Umbrueche,
      // wenn sie auf einen Doppelpunkt folgen
      // Siehe http://www.onlinebanking-forum.de/phpBB2/viewtopic.php?p=82519#82519
      text = PT_SPLIT.matcher(text).replaceAll(":");

      StringTokenizer st = new StringTokenizer(text, System.getProperty("line.separator", "\n"));
      HashMap values = new HashMap();

      while (st.hasMoreTokens()) {
        String line = st.nextToken();
        if (line == null || line.length() <= 0) continue;

        line = line.replaceAll("\\s", " ");

        int sep = line.indexOf(":");
        if (sep == -1) continue;

        values.put(line.substring(0, sep).trim(), line.substring(sep + 1).trim());
      }

      AuslandsUeberweisung u =
          (AuslandsUeberweisung)
              Settings.getDBService().createObject(AuslandsUeberweisung.class, null);

      Iterator i = values.keySet().iterator();
      while (i.hasNext()) {
        String s = (String) i.next();
        String value = (String) values.get(s);
        if (value == null || s == null) continue;
        if (PT_BLZ.matcher(s).matches()) u.setGegenkontoBLZ(value.replaceAll(" ", ""));
        else if (PT_KONTO.matcher(s).matches()) u.setGegenkontoNummer(value.replaceAll(" ", ""));
        else if (PT_NAME.matcher(s).matches()) u.setGegenkontoName(value);
        else if (PT_ZWECK.matcher(s).matches()) u.setZweck(value);
      }
      return u;
    } catch (Throwable t) {
      Logger.debug("unable to parse clipboard data: " + t.getMessage());
    }
    return null;
  }
 @SuppressWarnings("unchecked") // $NON-NLS-1$
 public void javaToNative(Object object, TransferData transferData) {
   Feature feature = (Feature) object;
   FeatureCollection collection = FeatureCollections.newCollection();
   collection.add(feature);
   FeatureTransformer transformer = new FeatureTransformer();
   transformer.setIndentation(4);
   try {
     TextTransfer.getInstance().javaToNative(transformer.transform(collection), transferData);
   } catch (TransformerException e) {
     throw (RuntimeException) new RuntimeException().initCause(e);
   }
 }
        /*
         * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
         */
        @Override
        public void dragSetData(DragSourceEvent event) {
          if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
            List<XViewerColumn> selCols = getVisibleTableSelection();
            Collection<String> ids = new ArrayList<String>(selCols.size());

            for (XViewerColumn xCol : selCols) {
              ids.add(xCol.getId());
            }

            event.data = CollectionsUtil.toString(ids, null, ", ", null);
          }
        }
  public void run() {
    String link = "";
    Clipboard clipBoard = new Clipboard(Display.getDefault());

    for (int i = 0; i < fileIDs.length; i++) {
      link += baseURL + fileIDs[i];
      if (fileIDs.length - 1 > i) link += (SWT.getPlatform().equals("win32") ? "\r\n" : "\n");
    }

    if (link != "" || link != null)
      clipBoard.setContents(new Object[] {link}, new Transfer[] {TextTransfer.getInstance()});
    clipBoard.dispose();
  }
Exemple #21
0
 /**
  * Set the clipboard contents. Prompt to retry if clipboard is busy.
  *
  * @param resources the resources to copy to the clipboard
  * @param fileNames file names of the resources to copy to the clipboard
  * @param names string representation of all names
  */
 private void setClipboard(IResource[] resources, String[] fileNames, String names) {
   try {
     // set the clipboard contents
     if (fileNames.length > 0) {
       clipboard.setContents(
           new Object[] {resources, fileNames, names},
           new Transfer[] {
             ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance()
           });
     } else {
       clipboard.setContents(
           new Object[] {resources, names},
           new Transfer[] {ResourceTransfer.getInstance(), TextTransfer.getInstance()});
     }
   } catch (SWTError e) {
     if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) throw e;
     if (MessageDialog.openQuestion(
         shell,
         CViewMessages.CopyToClipboardProblemDialog_title,
         CViewMessages.CopyToClipboardProblemDialog_message))
       setClipboard(resources, fileNames, names);
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
  */
 public boolean validateDrop(Object target, int operation, TransferData transferType) {
   if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
     if (fDropType == DROP_TYPE_EXPRESSION) {
       return validateExpressionDrop(target);
     } else if (fDropType == DROP_TYPE_VARIABLE) {
       return validateVariableDrop(target);
     } else if (fDropType == DROP_TYPE_WATCH_ADAPTABLE_ELEMENT) {
       return validateWatchAdaptableDrop(target);
     }
   } else if (TextTransfer.getInstance().isSupportedType(transferType)) {
     return validateTextDrop(target);
   }
   return false;
 }
Exemple #23
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    final Clipboard cb = new Clipboard(HandlerUtil.getActiveShellChecked(event).getDisplay());

    ISelection sel = HandlerUtil.getCurrentSelectionChecked(event);
    if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
      Object obj = ((IStructuredSelection) sel).getFirstElement();
      if (obj instanceof IWebResource) {
        TextTransfer transfer = TextTransfer.getInstance();
        cb.setContents(new Object[] {((IWebResource) obj).getLink()}, new Transfer[] {transfer});
      }
    }
    return null;
  }
 /** Returns the data to be transferred in a drag and drop operation. */
 @Override
 public void dragSetData(DragSourceEvent event) {
   if (event.doit == false) return;
   if (ModelDataTransfer.getInstance().isSupportedType(event.dataType)) {
     event.data = getSelectedModelObjects();
     fDragData = event.data;
     return;
   }
   if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
     event.data =
         createTextualRepresentation((IStructuredSelection) fSelectionProvider.getSelection());
     fDragData = null;
     return;
   }
 }
 /**
  * Translate the transfer type from this element.
  *
  * @param name The attribute name.
  * @return The transfer instance.
  */
 private Transfer parseTransferType(String name) {
   if ("TextTransfer".equals(name)) { // $NON-NLS-1$
     return TextTransfer.getInstance();
   }
   if ("ImageTransfer".equals(name)) { // $NON-NLS-1$
     return ImageTransfer.getInstance();
   }
   if ("FileTransfer".equals(name)) { // $NON-NLS-1$
     return FileTransfer.getInstance();
   }
   if ("LocalSelectionTransfer".equals(name)) { // $NON-NLS-1$
     return LocalSelectionTransfer.getTransfer();
   }
   return null;
 }
 @Override
 protected void execute(List<VType> data, ExecutionEvent event) {
   if (!data.isEmpty()) {
     VType value = data.get(0);
     if (export.canExport(value)) {
       StringWriter writer = new StringWriter();
       export.export(value, writer);
       String text = writer.toString();
       final Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
       clipboard.setContents(new String[] {text}, new Transfer[] {TextTransfer.getInstance()});
     } else {
       throw new RuntimeException("Copy operation for value " + value + " is not supported.");
     }
   }
 }
    /** @see Transfer#nativeToJava */
    @SuppressWarnings("deprecation")
    public Object nativeToJava(TransferData transferData) {
      String string = (String) TextTransfer.getInstance().nativeToJava(transferData);

      WKTReader reader = new WKTReader();
      try {
        Geometry read = reader.read(string);
        FeatureType ft =
            DataUtilities.createType(
                "Temp Type", "*geom:" + read.getClass().getName()); // $NON-NLS-1$ //$NON-NLS-2$
        return ft.create(new Object[] {read});
      } catch (Exception e) {
        UiPlugin.log("", e); // $NON-NLS-1$
      }
      return null;
    }
Exemple #28
0
  /**
   * Adds drag behavior to a Table field. Sets how the table field should behave when an item is
   * dragged inside it.
   *
   * @param table The table field
   */
  private void createDragSource(final Table table) {

    Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
    DragSource source = new DragSource(table, DND.DROP_MOVE);
    source.setTransfer(types);
    source.addDragListener(
        new DragSourceListener() {
          public void dragStart(DragSourceEvent event) {
            // Only start the drag if there is actually text in the
            // label - this text will be what is dropped on the target.
            if (table.getItems().length == 0) {
              event.doit = false;
            }
          }

          public void dragSetData(DragSourceEvent event) {
            // A drop has been performed, so provide the data of the
            // requested type.
            // (Checking the type of the requested data is only
            // necessary if the drag source supports more than
            // one data type but is shown here as an example).
            DragSource ds = (DragSource) event.widget;
            Table table = (Table) ds.getControl();
            TableItem[] selection = table.getSelection();

            StringBuffer buff = new StringBuffer();
            for (int i = 0, n = selection.length; i < n; i++) {
              buff.append(selection[i].getText());
            }

            event.data = buff.toString();
          }

          public void dragFinished(DragSourceEvent event) {
            // A Move operation has been performed so remove the data
            // from the source
            if (event.detail == DND.DROP_MOVE) {
              DragSource ds = (DragSource) event.widget;
              Table table = (Table) ds.getControl();
              int index = table.getSelectionIndex();

              table.remove(index);
            }
          }
        });
  }
Exemple #29
0
 /**
  * ************************************************************************* Copy selected source
  * rows ************************************************************************
  */
 public void copySelected() {
   GridItem[] selection = getGrid().getSelection();
   Clipboard clipboard = new Clipboard(Display.getCurrent());
   String data = "";
   for (GridItem item : selection) {
     if (!data.isEmpty()) data += "\n";
     String line = item.getText(CodeViewerColumn.CODE.ordinal());
     if (line != null) {
       line = line.trim();
     } else {
       line = "";
     }
     data += line;
   }
   clipboard.setContents(new Object[] {data}, new Transfer[] {TextTransfer.getInstance()});
   clipboard.dispose();
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
  */
 public boolean performDrop(Object data) {
   if (LocalSelectionTransfer.getTransfer().isSupportedType(fCurrentTransferType)) {
     IStructuredSelection selection =
         (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
     if (fDropType == DROP_TYPE_EXPRESSION) {
       return performExpressionDrop(selection);
     } else if (fDropType == DROP_TYPE_VARIABLE
         || fDropType == DROP_TYPE_WATCH_ADAPTABLE_ELEMENT) {
       return performVariableOrWatchAdaptableDrop(selection);
     }
   } else if (TextTransfer.getInstance().isSupportedType(fCurrentTransferType)) {
     if (data != null) {
       return performTextDrop((String) data);
     }
   }
   return false;
 }