/**
   * Closes the given channel and handle the given exception.
   *
   * @param channel The channel instance or <code>null</code>.
   * @param exception The exception to handle. Must be not <code>null</code>.
   */
  protected void handleException(IChannel channel, Throwable exception) {
    Assert.isNotNull(exception);

    // Close the backend channel
    if (channel != null) {
      final IChannel finChannel = channel;
      if (Protocol.isDispatchThread()) {
        finChannel.close();
      } else {
        Protocol.invokeAndWait(
            new Runnable() {
              @Override
              public void run() {
                finChannel.close();
              }
            });
      }
    }

    // Get the status handler
    IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(getClass());
    if (handler != null && handler.length > 0) {
      // If the exception is a core exception, we can pass on the status object to the handler
      IStatus status = null;
      if (exception instanceof CoreException) ((CoreException) exception).getStatus();
      else {
        // Construct the status from the exception
        status =
            new Status(
                IStatus.ERROR,
                UIPlugin.getUniqueIdentifier(),
                0,
                exception.getLocalizedMessage(),
                exception);
      }

      // Handle the status (Take the first status handler in the list)
      if (status != null) {
        IPropertiesContainer data = new PropertiesContainer();
        data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, getStatusDialogTitle());
        data.setProperty(
            IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, getStatusDialogContextHelpId());
        data.setProperty(
            IStatusHandlerConstants.PROPERTY_DONT_ASK_AGAIN_ID, getStatusDialogDontAskAgainKey());
        data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, this);

        handler[0].handleStatus(status, data, null);
      }
    }
  }
 private void doneLoadChildren(
     final FileInfo parent, final Throwable error, final FileInfo[] children) {
   assert Protocol.isDispatchThread();
   assert error == null || children == null;
   if (fDisplay == null) return;
   Arrays.sort(
       children,
       new Comparator<FileInfo>() {
         public int compare(FileInfo o1, FileInfo o2) {
           if (o1.isDir == o2.isDir) return o1.name.compareTo(o2.name);
           if (o1.isDir) return 1;
           return -1;
         }
       });
   int i = 0;
   for (FileInfo fileInfo : children) {
     fileInfo.index = i++;
   }
   fDisplay.asyncExec(
       new Runnable() {
         public void run() {
           assert parent.children_pending;
           assert parent.children == null;
           parent.children_pending = false;
           parent.children = children;
           parent.children_error = error;
           updateItems(parent);
         }
       });
 }
  /* (non-Javadoc)
   * @see org.eclipse.tm.tcf.protocol.Protocol.ChannelOpenListener#onChannelOpen(org.eclipse.tm.tcf.protocol.IChannel)
   */
  @Override
  public void onChannelOpen(IChannel channel) {
    Assert.isNotNull(channel);
    Assert.isTrue(Protocol.isDispatchThread());

    // Trace the channel opening
    LogUtils.logMessageForChannel(
        channel,
        Messages.InternalChannelOpenListener_onChannelOpen_message,
        "debug/channels",
        this); //$NON-NLS-1$

    // As the channel has just opened, there should be no channel listener, but better be safe and
    // check.
    IChannel.IChannelListener channelListener = channelListeners.remove(channel);
    if (channelListener != null) channel.removeChannelListener(channelListener);
    // Create a new channel listener instance
    channelListener = new InternalChannelListener(channel);
    // Add the channel listener to the global map
    setChannelListener(channel, channelListener);
    // Attach channel listener to the channel
    channel.addChannelListener(channelListener);

    // Fire the property change event for the channel
    Tcf.fireChannelStateChangeListeners(channel, IChannel.STATE_OPEN);
  }
 public void setInitialSelection(final String filename) {
   fPathToSelect = null;
   Protocol.invokeLater(
       new Runnable() {
         public void run() {
           fFileToSelect = filename;
         }
       });
 }
 private void handleDispose() {
   Protocol.invokeAndWait(
       new Runnable() {
         public void run() {
           disconnectPeer();
           fFileSystem = null;
           fDisplay = null;
         }
       });
 }
 public void setInput(IPeer peer) {
   if (peer == fPeer) {
     return;
   }
   if (fPeer != null) {
     Protocol.invokeAndWait(
         new Runnable() {
           public void run() {
             disconnectPeer();
           }
         });
   }
   fileTree.setItemCount(0);
   fRootInfo.children = null;
   fPeer = peer;
   if (fPeer != null) {
     Protocol.invokeAndWait(
         new Runnable() {
           public void run() {
             connectPeer();
           }
         });
   }
 }
示例#7
0
 private void onConnected(final Throwable x) {
   Protocol.invokeLater(
       new Runnable() {
         public void run() {
           if (x != null) {
             terminate(x);
             closed = true;
           }
           if (closed) {
             try {
               if (out != null) out.close();
               if (inp != null) inp.close();
             } catch (IOException y) {
               Protocol.log("Cannot close pipe", y);
             }
           } else {
             started = true;
             start();
           }
         }
       });
 }
  private void loadChildren(final FileInfo parent) {
    assert Thread.currentThread() == fDisplay.getThread();
    if (parent.children_pending) return;
    assert parent.children == null;
    parent.children_pending = true;
    parent.children_error = null;
    Protocol.invokeLater(
        new Runnable() {
          public void run() {
            final IFileSystem fs = fFileSystem;
            if (fs == null || !canHaveChildren(parent)) {
              doneLoadChildren(parent, null, new FileInfo[0]);
              return;
            }
            if (parent.fullname == null) {
              fs.roots(
                  new IFileSystem.DoneRoots() {
                    public void doneRoots(
                        IToken token, FileSystemException error, DirEntry[] entries) {
                      if (error != null) {
                        doneLoadChildren(parent, error, null);
                      } else {
                        final List<FileInfo> fileInfos = new ArrayList<FileInfo>(entries.length);
                        for (DirEntry entry : entries) {
                          FileInfo info = new FileInfo();
                          info.parent = parent;
                          String name = entry.filename;
                          int length = name.length();
                          if (length > 1 && (name.endsWith("\\") || name.endsWith("/"))) {
                            name = name.substring(0, length - 1);
                          }
                          info.name = name;
                          info.fullname = entry.longname != null ? entry.longname : entry.filename;
                          info.isDir = entry.attrs != null ? entry.attrs.isDirectory() : false;
                          if (!fDirectoriesOnly || info.isDir) {
                            fileInfos.add(info);
                          }
                        }
                        doneLoadChildren(
                            parent, null, fileInfos.toArray(new FileInfo[fileInfos.size()]));
                      }
                    }
                  });
              return;
            }
            fs.opendir(
                parent.fullname,
                new IFileSystem.DoneOpen() {
                  final List<FileInfo> fileInfos = new ArrayList<FileInfo>();

                  public void doneOpen(
                      IToken token, FileSystemException error, final IFileHandle handle) {
                    if (error != null) {
                      doneLoadChildren(parent, error, null);
                      return;
                    }
                    fs.readdir(
                        handle,
                        new IFileSystem.DoneReadDir() {
                          public void doneReadDir(
                              IToken token,
                              FileSystemException error,
                              DirEntry[] entries,
                              boolean eof) {
                            if (entries != null) {
                              for (DirEntry entry : entries) {
                                FileInfo info = new FileInfo();
                                info.parent = parent;
                                info.name = entry.filename;
                                info.fullname =
                                    entry.longname != null
                                        ? entry.longname
                                        : (new Path(parent.fullname).append(info.name).toString());
                                info.isDir =
                                    entry.attrs != null ? entry.attrs.isDirectory() : false;
                                if (!fDirectoriesOnly || info.isDir) {
                                  fileInfos.add(info);
                                }
                              }
                            }
                            if (error != null || eof) {
                              fs.close(
                                  handle,
                                  new IFileSystem.DoneClose() {
                                    public void doneClose(IToken token, FileSystemException error) {
                                      // ignore error
                                    }
                                  });
                              int size = fileInfos.size();
                              if (size == 0 && error != null) {
                                doneLoadChildren(parent, error, null);
                              } else {
                                doneLoadChildren(
                                    parent, null, fileInfos.toArray(new FileInfo[size]));
                              }
                            } else {
                              fs.readdir(handle, this);
                            }
                          }
                        });
                  }
                });
          }
        });
  }