@Nullable
  public PsiElement[] getElements(boolean[] isCopied) {
    try {
      Transferable content = myCopyPasteManager.getContents();
      if (content == null) {
        return null;
      }

      Object transferData;
      try {
        transferData = content.getTransferData(ourDataFlavor);
      } catch (UnsupportedFlavorException e) {
        return null;
      } catch (IOException e) {
        return null;
      }

      if (!(transferData instanceof MyData)) {
        return null;
      }
      MyData dataProxy = (MyData) transferData;
      if (!Comparing.equal(dataProxy, myRecentData)) {
        return null;
      }
      if (isCopied != null) {
        isCopied[0] = myRecentData.isCopied();
      }
      return myRecentData.getElements();
    } catch (Exception e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(e);
      }
      return null;
    }
  }
 public static void main(String[] args) throws Exception {
   Peer master = null;
   try {
     Peer[] peers = ExampleUtils.createAndAttachNodes(100, 4001);
     master = peers[0];
     MyPeer myPeer = new MyPeer(master);
     ExampleUtils.bootstrap(peers);
     myPeer
         .put(
             "This is my location key",
             "This is my domain",
             "This is my content key",
             "And here comes the data")
         .awaitUninterruptibly();
     FutureDHT futureDHT =
         myPeer.get("This is my location key", "This is my domain", "This is my content key");
     futureDHT.awaitUninterruptibly();
     System.err.println(futureDHT.getFailedReason());
     Map<Number160, Data> map = futureDHT.getDataMap();
     for (Data data : map.values()) {
       MyData myData = (MyData) data.getObject();
       System.out.println(
           "key: "
               + myData.getKey()
               + ", domain: "
               + myData.getDomain()
               + ", content: "
               + myData.getContent()
               + ", data: "
               + myData.getData());
     }
   } finally {
     master.halt();
   }
 }
    @Nullable
    public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
      if (ourDataFlavor.equals(flavor)) {
        return myDataProxy;
      } else if (DataFlavor.stringFlavor.equals(flavor)) {
        return getDataAsText();
      } else if (DataFlavor.javaFileListFlavor.equals(flavor)) {
        return getDataAsFileList();
      } else if (flavor.equals(LinuxDragAndDropSupport.uriListFlavor)) {
        final List<File> files = getDataAsFileList();
        if (files != null) {
          return LinuxDragAndDropSupport.toUriList(files);
        }
      } else if (flavor.equals(LinuxDragAndDropSupport.gnomeFileListFlavor)) {
        final List<File> files = getDataAsFileList();
        if (files != null) {
          final String string =
              (myDataProxy.isCopied() ? "copy\n" : "cut\n")
                  + LinuxDragAndDropSupport.toUriList(files);
          return new ByteArrayInputStream(string.getBytes(CharsetToolkit.UTF8_CHARSET));
        }
      } else if (flavor.equals(LinuxDragAndDropSupport.kdeCutMarkFlavor)
          && !myDataProxy.isCopied()) {
        return new ByteArrayInputStream("1".getBytes());
      }

      return null;
    }
    public boolean createSecondaryKey(
        SecondaryDatabase secondaryDb,
        DatabaseEntry keyEntry,
        DatabaseEntry dataEntry,
        DatabaseEntry resultEntry) {

      /*
       * Convert the data entry to a MyData object, extract the secondary
       * key value from it, and then convert it to the resulting
       * secondary key entry.
       */
      MyData data = dataBinding.entryToObject(dataEntry);
      String key = data.getMessage();
      if (key != null) {
        secKeyBinding.objectToEntry(key, resultEntry);
        return true;
      } else {

        /*
         * The message property of MyData is optional, so if it is null
         * then return false to prevent it from being indexed.  Note
         * that if a required key is missing or an error occurs, an
         * exception should be thrown by this method.
         */
        return false;
      }
    }
 public boolean isCutElement(Object element) {
   if (myRecentData == null) return false;
   if (myRecentData.isCopied()) return false;
   PsiElement[] elements = myRecentData.getElements();
   if (elements == null) return false;
   for (PsiElement aElement : elements) {
     if (aElement == element) return true;
   }
   return false;
 }
 private FutureDHT put(String key, String domain, String content, String data)
     throws IOException {
   Number160 locationKey = Number160.createHash(key);
   Number160 domainKey = Number160.createHash(domain);
   Number160 contentKey = Number160.createHash(content);
   MyData myData = new MyData();
   myData.setKey(key);
   myData.setDomain(domain);
   myData.setContent(content);
   myData.setData(data);
   return peer.put(locationKey)
       .setDomainKey(domainKey)
       .setData(contentKey, new Data(myData))
       .start();
 }
Exemple #7
0
 public static void main(String[] args) {
   Connection con = null;
   PreparedStatement stmt = null;
   try {
     System.out.println("Enrollment:130050131531");
     MyData m1 = new MyData();
     con = m1.SetConnection("s2a130050131531");
     stmt = con.prepareStatement("Select display()");
     ResultSet rs = stmt.executeQuery();
     while (rs.next()) {
       System.out.println(rs.getString("display"));
     }
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
 }
 @Nullable
 private List<File> getDataAsFileList() {
   final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
   try {
     return asFileList(myDataProxy.getElements());
   } finally {
     token.finish();
   }
 }
Exemple #9
0
 public Object getTransferData(DataFlavor flavor)
     throws UnsupportedFlavorException, IOException {
   if (ourDataFlavor.equals(flavor)) {
     return myDataProxy;
   }
   if (DataFlavor.stringFlavor.equals(flavor)) {
     return getDataAsText();
   }
   if (DataFlavor.javaFileListFlavor.equals(flavor)) {
     return asFileList(myDataProxy.getElements());
   }
   return null;
 }
Exemple #10
0
 @Nullable
 private String getDataAsText() {
   List<String> names = new ArrayList<String>();
   for (PsiElement element : myDataProxy.getElements()) {
     if (element instanceof PsiNamedElement) {
       String name = ((PsiNamedElement) element).getName();
       if (name != null) {
         names.add(name);
       }
     }
   }
   if (names.isEmpty()) {
     return null;
   }
   return StringUtil.join(names, "\n");
 }
 @Nullable
 private String getDataAsText() {
   final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
   try {
     final List<String> names = new ArrayList<String>();
     for (PsiElement element : myDataProxy.getElements()) {
       if (element instanceof PsiNamedElement) {
         String name = ((PsiNamedElement) element).getName();
         if (name != null) {
           names.add(name);
         }
       }
     }
     return names.isEmpty() ? null : StringUtil.join(names, "\n");
   } finally {
     token.finish();
   }
 }
 public PsiElement[] getElements() {
   return myDataProxy.getElements();
 }
 public DataFlavor[] getTransferDataFlavors() {
   return myDataProxy.isCopied() ? DATA_FLAVORS_COPY : DATA_FLAVORS_CUT;
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MyData myData = new MyData();
    myData.setData("1001");
    myData.setValue("ol");
    list.add(myData);

    myData = new MyData();
    myData.setData("1002");
    myData.setValue("oll");
    list.add(myData);

    myData = new MyData();
    myData.setData("1003");
    myData.setValue("olll");
    list.add(myData);

    myData = new MyData();
    myData.setData("1004");
    myData.setValue("olplp");
    list.add(myData);

    myData = new MyData();
    myData.setData("1005");
    myData.setValue("olodkf");
    list.add(myData);

    ListView listView = (ListView) findViewById(R.id.listView);
    MyAdapter myAdapter = new MyAdapter(this, list);
    listView.setAdapter(myAdapter);
  }