public void setActive(boolean b) {
    // the function is called 3 times when leaving this perspective this odd
    // logic is here so it doesn't reload the data when leaving this perspective
    if (b) {
      if (!this.isActive) {
        System.out.println("create eclResults setActive");
        if (System.getProperties().getProperty("resultsFile") != null
            && !System.getProperties().getProperty("resultsFile").equals("")) {
          String xmlFile = System.getProperties().getProperty("resultsFile");
          ArrayList<String> resultFiles = parseData("resultsFile");
          for (int i = 0; i < resultFiles.size(); i++) {
            openResultsXML(resultFiles.get(i));
          }
          // openResultsXML(xmlFile);
          System.getProperties().setProperty("resultsFile", "");
        }
        int len = folder.getItemCount();
        folder.setSelection(len - 1);
        this.isActive = true;
      } else {
        this.isActive = false;
      }

    } else {
      System.out.println("create eclResults setActive -- deactivate");
    }
  }
  public ArrayList parseData(String propName) {
    ArrayList<String> files = new ArrayList();
    String saltData = "";
    try {
      if (System.getProperty(propName) != null) {
        saltData = System.getProperty(propName);
      }
      StringTokenizer fileTokens = new StringTokenizer(saltData, ",");
      while (fileTokens.hasMoreElements()) {
        String file = fileTokens.nextToken();

        if (file != null && !file.equals("null") && !file.equals("")) {
          System.out.println("Built tab from list" + file);

          files.add(file);
        }
      }
      saltData = "";
    } catch (Exception e) {
      System.out.println("Failed to open files ");
    }
    // just incase it was a signle node
    if (saltData != null && !saltData.equals("null") && !saltData.equals("")) {
      System.out.println("Built tab from single " + saltData);
      files.add(saltData);
    }
    System.setProperty(propName, "");
    return files;
  }
  public void openProfiles_old() {
    String saltData = "";
    try {
      if (System.getProperty("saltData") != null) {
        saltData = System.getProperty("saltData");
      }
      StringTokenizer fileTokens = new StringTokenizer(saltData, ",");
      while (fileTokens.hasMoreElements()) {
        String file = fileTokens.nextToken();

        if (file != null && !file.equals("null") && !file.equals("")) {
          System.out.println("Built tab from list" + file);
          buildProfileTab(file);
        }
      }
      saltData = "";
    } catch (Exception e) {
      System.out.println("Failed to open files ");
    }
    // just incase it was a signle node
    if (saltData != null && !saltData.equals("null") && !saltData.equals("")) {
      System.out.println("Built tab from single " + saltData);
      buildProfileTab(saltData);
    }
    System.setProperty("saltData", "");
  }
示例#4
0
文件: View.java 项目: shader/gdr
  /**
   * Initialize the toolbar with icons and selection listeners in the appropriate part of the window
   */
  public void initToolbar() {

    Device dev = shell.getDisplay();
    try {
      exitImg = new Image(dev, "img/exit.png");
      //            openImg = new Image(dev, "img/open.png");
      playImg = new Image(dev, "img/play.png");
      //            pauseImg = new Image(dev, "img/pause.png");

    } catch (Exception e) {
      System.out.println("Cannot load images");
      System.out.println(e.getMessage());
      System.exit(1);
    }

    ToolBar toolBar = new ToolBar(shell, SWT.BORDER);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    toolBar.setLayoutData(gridData);

    ToolItem exit = new ToolItem(toolBar, SWT.PUSH);
    exit.setImage(exitImg);

    // ToolItem open = new ToolItem(toolBar, SWT.PUSH);
    // exit.setImage(openImg);

    ToolItem play = new ToolItem(toolBar, SWT.PUSH);
    play.setImage(playImg);

    //        ToolItem pause = new ToolItem(toolBar, SWT.PUSH);
    //        pause.setImage(pauseImg);

    toolBar.pack();

    exit.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.exit(0);
          }
        });

    // open.addSelectionListener(new SelectionAdapter() {
    //     @Override
    //     public void widgetSelected(SelectionEvent e) {
    //         FileDialog dialog = new FileDialog(shell, SWT.NULL);
    //         String path = dialog.open();
    //     }
    // });

    play.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            controller.RunAnimation();
          }
        });
  }
  public void openUrl(String url) {
    String os = System.getProperty("os.name");
    Runtime runtime = Runtime.getRuntime();
    try {
      // Block for Windows Platform
      if (os.startsWith("Windows")) {
        String cmd = "rundll32 url.dll,FileProtocolHandler " + url;
        Process p = runtime.exec(cmd);

        // Block for Mac OS
      } else if (os.startsWith("Mac OS")) {
        Class fileMgr = Class.forName("com.apple.eio.FileManager");
        Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
        openURL.invoke(null, new Object[] {url});

        // Block for UNIX Platform
      } else {
        String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape"};
        String browser = null;
        for (int count = 0; count < browsers.length && browser == null; count++)
          if (runtime.exec(new String[] {"which", browsers[count]}).waitFor() == 0)
            browser = browsers[count];

        if (browser == null) throw new Exception("Could not find web browser");
        else runtime.exec(new String[] {browser, url});
      }
    } catch (Exception x) {
      System.err.println("Exception occurd while invoking Browser!");
      x.printStackTrace();
    }
  }
示例#6
0
 private void exitMenuItemWidgetSelected(SelectionEvent evt) {
   try {
     // Save app settings to file
     appSettings.store(new FileOutputStream("appsettings.ini"), "");
   } catch (FileNotFoundException e) {
   } catch (IOException e) {
   }
   getShell().dispose();
   System.exit(1);
 }
 /**
  * Return the computer full name. <br>
  *
  * @return the name or <b>null</b> if the name cannot be found
  */
 public static String getComputerFullName() {
   String uname = System.getProperty("user.name");
   if (uname == null || uname.isEmpty()) {
     try {
       final InetAddress addr = InetAddress.getLocalHost();
       uname = addr.getHostName();
     } catch (final Exception e) {
     }
   }
   return uname;
 }
示例#8
0
文件: FindTool.java 项目: URMC/i2b2
  public List getCategories() {
    List concepts = null;
    try {
      //		GetReturnType request = new GetReturnType();
      //		request.setType("limited");

      GetCategoriesType request = new GetCategoriesType();
      request.setType("core");
      request.setHiddens(false);
      request.setSynonyms(false);

      OntologyResponseMessage msg = new OntologyResponseMessage();
      StatusType procStatus = null;
      while (procStatus == null || !procStatus.getType().equals("DONE")) {
        String response = OntServiceDriver.getCategories(request, "FIND");
        procStatus = msg.processResult(response);
        //				if  other error codes
        //				TABLE_ACCESS_DENIED and USER_INVALID, DATABASE ERROR
        if (procStatus.getType().equals("ERROR")) {
          System.setProperty("errorMessage", procStatus.getValue());
          return concepts;
        }
        procStatus.setType("DONE");
      }
      ConceptsType allConcepts = msg.doReadConcepts();
      if (allConcepts != null) concepts = allConcepts.getConcept();

    } catch (AxisFault e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", "Ontology cell unavailable");
    } catch (I2B2Exception e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", e.getMessage());
    } catch (Exception e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", "Remote server unavailable");
    }

    return concepts;
  }
  private String buildFileDialog() {

    // file field
    FileDialog fd = new FileDialog(parentShell, SWT.SAVE);

    fd.setText("Open");
    fd.setFilterPath("C:/");
    String[] filterExt = {"*.xml", "*.csv", "*.*"};
    fd.setFilterExtensions(filterExt);
    String selected = fd.open();
    if (!(fd.getFileName()).equalsIgnoreCase("")) {
      return fd.getFilterPath() + System.getProperty("file.separator") + fd.getFileName();
    } else {
      return "";
    }
  }
  protected void setupPortEditors() {
    viewer.setCellEditors(new CellEditor[] {null, new TextCellEditor(ports)});

    ICellModifier cellModifier =
        new ICellModifier() {
          public Object getValue(Object element, String property) {
            ServerPort sp = (ServerPort) element;
            if (sp.getPort() < 0) return "-";
            return sp.getPort() + "";
          }

          public boolean canModify(Object element, String property) {
            if ("port".equals(property)) return true;

            return false;
          }

          public void modify(Object element, String property, Object value) {
            try {
              Item item = (Item) element;
              ServerPort sp = (ServerPort) item.getData();
              int port = Integer.parseInt((String) value);
              execute(new ModifyPortCommand(tomcatConfiguration, sp.getId(), port));
            } catch (Exception ex) {
              // ignore
            }
          }
        };
    viewer.setCellModifier(cellModifier);

    // preselect second column (Windows-only)
    String os = System.getProperty("os.name");
    if (os != null && os.toLowerCase().indexOf("win") >= 0) {
      ports.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              try {
                int n = ports.getSelectionIndex();
                viewer.editElement(ports.getItem(n).getData(), 1);
              } catch (Exception e) {
                // ignore
              }
            }
          });
    }
  }
 public static boolean test() {
   int fail = 0;
   String url;
   String pluginPath = System.getProperty("PLUGIN_PATH");
   if (verbose) System.out.println("PLUGIN_PATH <" + pluginPath + ">");
   if (pluginPath == null)
     url = Browser5.class.getClassLoader().getResource("browser5.html").toString();
   else url = pluginPath + "/data/browser5.html";
   String[] urls = {url};
   for (int i = 0; i < urls.length; i++) {
     // TEST1 TEMPORARILY NOT RUN FOR MOZILLA
     if (!isMozilla) {
       boolean result = test1(urls[i]);
       if (verbose) System.out.print(result ? "." : "E");
       if (!result) fail++;
     }
   }
   return fail == 0;
 }
示例#12
0
 // --------------------------------------------------------------------------------
 private void onSashResize() {
   if (System.currentTimeMillis() >= initializedTime + 3000) {
     prop.setProperty(DOCUMENT_COMPOSITE_WEIGHT, sashForm.getWeights());
   }
 }
示例#13
0
  // --------------------------------------------------------------------------------
  public void init2() {
    parent.setLayout(new FormLayout());

    sashForm = new SashForm(parent, SWT.SMOOTH | SWT.VERTICAL);
    FormData fd_sashForm1 = new FormData();
    fd_sashForm1.top = new FormAttachment(0, 1);
    fd_sashForm1.left = new FormAttachment(0, 1);
    fd_sashForm1.right = new FormAttachment(100, -1);
    fd_sashForm1.bottom = new FormAttachment(100, -1);
    sashForm.setLayoutData(fd_sashForm1);

    tree = new Tree(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
    tree.setHeaderVisible(true);

    FormData d1 = new FormData();
    d1.top = new FormAttachment(0, 1);
    d1.left = new FormAttachment(0, 1);
    d1.right = new FormAttachment(100, -1);
    d1.bottom = new FormAttachment(100, -1);
    tree.setLayoutData(d1);

    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
    column2.setText("Data Type");

    editorComposite = new Composite(sashForm, SWT.BORDER);
    editorComposite.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent e) {
            onSashResize();
          }
        });

    FormData fd_composite1 = new FormData();
    fd_composite1.top = new FormAttachment(0, 1);
    fd_composite1.bottom = new FormAttachment(0, 35);
    fd_composite1.right = new FormAttachment(100, -1);
    fd_composite1.left = new FormAttachment(0, 1);
    editorComposite.setLayoutData(fd_composite1);
    editorComposite.setLayout(new FormLayout());
    Label nameLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_nameLabel = new FormData();
    fd_nameLabel.right = new FormAttachment(0, 66);
    fd_nameLabel.bottom = new FormAttachment(0, 32);
    fd_nameLabel.top = new FormAttachment(0, 12);
    fd_nameLabel.left = new FormAttachment(0, 10);
    nameLabel.setLayoutData(fd_nameLabel);
    nameLabel.setText("Name :");
    Label valueLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_valueLabel = new FormData();
    fd_valueLabel.top = new FormAttachment(nameLabel, 15);
    fd_valueLabel.left = new FormAttachment(0, 10);
    fd_valueLabel.bottom = new FormAttachment(nameLabel, 34, SWT.BOTTOM);
    fd_valueLabel.right = new FormAttachment(nameLabel, 0, SWT.RIGHT);
    valueLabel.setLayoutData(fd_valueLabel);
    valueLabel.setText("Value :");

    valueText =
        new Text(
            editorComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    valueText.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            verifyData();
          }
        });
    valueText.setEnabled(false);
    valueText.setEditable(false);
    FormData fd_valueText = new FormData();
    fd_valueText.top = new FormAttachment(nameLabel, 5);
    fd_valueText.bottom = new FormAttachment(100, -80);
    fd_valueText.right = new FormAttachment(100, -20);
    fd_valueText.left = new FormAttachment(valueLabel, 0, SWT.RIGHT);
    valueText.setLayoutData(fd_valueText);

    updateButton = new Button(editorComposite, SWT.NONE);
    updateButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            onUpdateButtonSelect();
          }
        });
    updateButton.setEnabled(false);
    FormData fd_updateButton = new FormData();
    fd_updateButton.left = new FormAttachment(100, -120);
    fd_updateButton.right = new FormAttachment(valueText, 0, SWT.RIGHT);
    updateButton.setLayoutData(fd_updateButton);
    updateButton.setText("Update");

    typeCombo = new Combo(editorComposite, SWT.READ_ONLY);
    fd_updateButton.top = new FormAttachment(typeCombo, 10);
    typeCombo.setEnabled(false);
    FormData fd_typeList = new FormData();
    fd_typeList.left = new FormAttachment(valueText, 0, SWT.LEFT);
    fd_typeList.top = new FormAttachment(valueText, 5, SWT.BOTTOM);
    // fd_typeList.bottom = new FormAttachment(valueText, 30, SWT.BOTTOM);
    fd_typeList.right = new FormAttachment(valueText, 170, SWT.LEFT);
    typeCombo.setLayoutData(fd_typeList);

    typeCombo.add("Double");
    typeCombo.add("Integer");
    typeCombo.add("Long");
    typeCombo.add("String");
    typeCombo.add("List (BasicDBList)");
    typeCombo.add("Map (BasicDBObject)");
    typeCombo.add("Date");
    typeCombo.add("ObjectId");
    typeCombo.add("JavaScript code");
    typeCombo.add("Binary data");
    typeCombo.add("Boolean");
    typeCombo.add("Null");
    typeCombo.add("Regular expression");
    typeCombo.add("Symbol");
    typeCombo.add("JavaScript code with scope");
    typeCombo.add("Timestamp");
    typeCombo.add("Min key");
    typeCombo.add("Max key");

    typeCombo.addListener(SWT.Selection, this);

    typeComboIndexMap.put(Double.class, new Integer(0));
    typeComboIndexMap.put(Integer.class, new Integer(1));
    typeComboIndexMap.put(Long.class, new Integer(2));
    typeComboIndexMap.put(String.class, new Integer(3));
    typeComboIndexMap.put(com.mongodb.BasicDBList.class, new Integer(4));
    typeComboIndexMap.put(com.mongodb.BasicDBObject.class, new Integer(5));
    typeComboIndexMap.put(java.util.Date.class, new Integer(6));
    typeComboIndexMap.put(org.bson.types.ObjectId.class, new Integer(7));
    typeComboIndexMap.put(org.bson.types.Code.class, new Integer(8));
    typeComboIndexMap.put(byte[].class, new Integer(9));
    typeComboIndexMap.put(Boolean.class, new Integer(10));
    typeComboIndexMap.put(java.util.regex.Pattern.class, new Integer(12));
    typeComboIndexMap.put(org.bson.types.Symbol.class, new Integer(13));
    typeComboIndexMap.put(org.bson.types.CodeWScope.class, new Integer(14));
    typeComboIndexMap.put(org.bson.types.BSONTimestamp.class, new Integer(15));
    typeComboIndexMap.put(org.bson.types.MinKey.class, new Integer(16));
    typeComboIndexMap.put(org.bson.types.MaxKey.class, new Integer(17));

    Label typeLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_typeLabel = new FormData();
    fd_typeLabel.top = new FormAttachment(typeCombo, 3, SWT.TOP);
    fd_typeLabel.left = new FormAttachment(nameLabel, 0, SWT.LEFT);
    typeLabel.setLayoutData(fd_typeLabel);
    typeLabel.setText("Type :");

    nameText = new Text(editorComposite, SWT.READ_ONLY);
    nameText.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
    FormData fd_nameText = new FormData();
    fd_nameText.top = new FormAttachment(nameLabel, -2, SWT.TOP);
    fd_nameText.left = new FormAttachment(valueText, 0, SWT.LEFT);
    fd_nameText.right = new FormAttachment(valueText, 0, SWT.RIGHT);
    nameText.setLayoutData(fd_nameText);

    MSwtUtil.getTreeColumnWidthFromProperties("documentTree", tree, prop, new int[] {150, 150});

    // listeners
    tree.addListener(SWT.MouseDoubleClick, this);
    tree.addListener(SWT.Selection, this);
    tree.addListener(SWT.KeyDown, this);
    MSwtUtil.addListenerToTreeColumns2(tree, this);

    documentImage = MUtil.getImage(parent.getShell().getDisplay(), "table.png");
    oidImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_star.png");
    intImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_blue.png");
    longImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_red.png");
    doubleImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_orange.png");
    stringImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_green.png");
    dateImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_white.png");
    boolImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_yellow.png");
    listImage = MUtil.getImage(parent.getShell().getDisplay(), "stop_blue.png");
    mapImage = MUtil.getImage(parent.getShell().getDisplay(), "stop_green.png");
    nullImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_black.png");
    jsImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_right.png");

    if (prop.containsKey(DOCUMENT_COMPOSITE_WEIGHT)) {

      (new Thread() {
            public void run() {
              // System.out.println( "e" );
              MSystemUtil.sleep(0);
              // System.out.println( "a" );
              shell
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        public void run() { // ----
                          // debug( "--" + prop.getIntArrayProperty( DOCUMENT_COMPOSITE_WEIGHT )[ 0
                          // ] );
                          sashForm.setWeights(prop.getIntArrayProperty(DOCUMENT_COMPOSITE_WEIGHT));
                        }
                      }); // ----
            }
          })
          .start();

    } else {
      sashForm.setWeights(new int[] {70, 30});
    }
    initializedTime = System.currentTimeMillis();
  }
示例#14
0
  private void openAddressBook() {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);

    fileDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"});
    fileDialog.setFilterNames(
        new String[] {
          resAddressBook.getString("Book_filter_name") + " (*.adr)",
          resAddressBook.getString("All_filter_name") + " (*.*)"
        });
    String name = fileDialog.open();

    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resAddressBook.getString("File")
              + file.getName()
              + " "
              + resAddressBook.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resAddressBook.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    int writeIndex = 0;
    for (int i = 0; i < data.length; i++) {
      String[] line = decodeLine(data[i]);
      if (line != null) tableInfo[writeIndex++] = line;
    }
    if (writeIndex != data.length) {
      String[][] result = new String[writeIndex][table.getColumnCount()];
      System.arraycopy(tableInfo, 0, result, 0, writeIndex);
      tableInfo = result;
    }
    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName());
    isModified = false;
    this.file = file;
  }
  private void openAddressBook(String name) {
    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resMessages.getString("File")
              + file.getName()
              + " "
              + resMessages.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resMessages.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resMessages.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);
      waitCursor.dispose();

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resMessages.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    for (int i = 0; i < data.length; i++) {
      tableInfo[i] = decodeLine(data[i]);
    }

    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resMessages.getString("Title_bar") + file.getName());
    isModified = false;
    this.file = file;
  }
示例#16
0
public class BuddiesViewer extends SkinView {

  private static final boolean SHOW_ONLINE_STATUS =
      System.getProperty("az.buddy.show_online", "1").equals("1");

  public static final int none_active_mode = 0;

  public static final int edit_mode = 1;

  public static final int share_mode = 2;

  public static final int invite_mode = 3;

  public static final int add_buddy_mode = 4;

  public static final int disabled_mode = 5;

  private Composite avatarsPanel = null;

  private Composite parent = null;

  private SWTSkin skin = null;

  private int avatarHightLightBorder;

  private int avatarImageBorder;

  private Point avatarImageSize = null;

  private Point avatarNameSize = null;

  private Point avatarSize = null;

  private int hSpacing;

  private List avatarWidgets = new ArrayList();

  private boolean isShareMode = false;

  private boolean isEditMode = false;

  private boolean isAddBuddyMode = false;

  private boolean isEnabled = true;

  private Color textColor = null;

  private Color selectedTextColor = null;

  private Color textLinkColor = null;

  private Color imageBorderColor = null;

  private Color selectedColor = null;

  private Color highlightedColor = null;

  private SWTSkinObject soNoBuddies;

  private com.aelitis.azureus.ui.swt.shells.friends.SharePage sharePage;

  private List buddiesList;

  private boolean reorder_outstanding;

  private Chat chat;

  private Color colorFileDragBorder;

  private Color colorFileDragBG;

  private ScrolledComposite scrollable;

  public BuddiesViewer() {

    chat = new Chat();
    chat.addChatListener(
        new ChatListener() {
          public void newMessage(final VuzeBuddy from, final ChatMessage message) {
            final AvatarWidget avatarWidget = findWidget(from);
            if (avatarWidget != null) {
              avatarWidget.setChatDiscussion(chat.getChatDiscussionFor(from));
              BuddyPlugin plugin = VuzeBuddyManager.getBuddyPlugin();
              if (plugin != null) {
                BooleanParameter enabledNotifictions = plugin.getEnableChatNotificationsParameter();

                if (!message.isMe() && enabledNotifictions.getValue()) {
                  avatarWidget
                      .getControl()
                      .getDisplay()
                      .asyncExec(
                          new Runnable() {
                            public void run() {
                              boolean isVisible = true;
                              if (avatarsPanel != null) {
                                if (!avatarsPanel.isVisible()) {
                                  isVisible = false;
                                }
                                /*Shell mainShell = avatarsPanel.getShell();
                                boolean mVisible = mainShell.isVisible();
                                boolean mEnabled = mainShell.isEnabled();
                                boolean mGetEnabled = mainShell.getEnabled();
                                boolean isFC = mainShell.isFocusControl();
                                Shell activeShell = mainShell.getDisplay().getActiveShell();*/
                                if (avatarsPanel.getShell().getDisplay().getActiveShell() == null) {
                                  isVisible = false;
                                }
                              }
                              // boolean isVisible = BuddiesViewer.this.isEnabled();
                              // avatarWidget.isChatWindowVisible();
                              if (!isVisible) {

                                new MessageNotificationWindow(avatarWidget, message);

                                /*
                                 * KN: MessageNotificationWindow above should really be moved into requestUserAttention()
                                 * so it can be handled in a platform-specific way if need be
                                 */
                                UserAlerts.requestUserAttention(
                                    PlatformManager.USER_REQUEST_INFO, null);
                              }
                            }
                          });
                }
              }
            }
          }

          public void updatedChat(VuzeBuddy buddy) {
            final AvatarWidget avatarWidget = findWidget(buddy);
            if (avatarWidget != null) {
              avatarWidget.setChatDiscussion(chat.getChatDiscussionFor(buddy));
            }
          }
        });

    /*
     * backed this change out as the desired behaviour is to continue showing
     * buddies when logged out as all attempts to do something with buddy will
     * prompt for login
     *
    LoginInfoManager.getInstance().addListener(
    	new ILoginInfoListener()
    	{
    		public void
    		loginUpdate(
    			LoginInfo 	info,
    			boolean 	isNewLoginID )
    		{
    			Utils.execSWTThreadLater(0, new AERunnable() {
    				public void
    				runSupport()
    				{
    					boolean logged_in = LoginInfoManager.getInstance().isLoggedIn();

    					boolean show_no_buddies = avatarWidgets.size() < 1 || !logged_in;

    					showNoBuddiesPanel( show_no_buddies );
    				}
    			});
    		}
    	});
    	*/
  }

  public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
    skin = skinObject.getSkin();

    SWTSkinProperties properties = skin.getSkinProperties();
    colorFileDragBorder = properties.getColor("color.buddy.filedrag.bg.border");
    colorFileDragBG = properties.getColor("color.buddy.filedrag.bg");

    soNoBuddies = skin.getSkinObject("buddies-viewer-nobuddies-panel");

    SWTSkinObject viewer = skin.getSkinObject(SkinConstants.VIEWID_BUDDIES_VIEWER);

    if (null != viewer) {

      parent = (Composite) skinObject.getControl();
      parent.setBackgroundMode(SWT.INHERIT_FORCE);
      scrollable = new ScrolledComposite(parent, SWT.V_SCROLL);
      scrollable.setExpandHorizontal(true);
      scrollable.setExpandVertical(true);
      scrollable.setBackgroundMode(SWT.INHERIT_FORCE);
      scrollable.getVerticalBar().setIncrement(10);
      scrollable.getVerticalBar().setPageIncrement(65);

      FormData fd = new FormData();
      fd.top = new FormAttachment(0, 0);
      fd.bottom = new FormAttachment(100, 0);
      fd.left = new FormAttachment(0, 0);
      fd.right = new FormAttachment(100, 0);
      scrollable.setLayoutData(fd);

      avatarsPanel = new Composite(scrollable, SWT.NONE);
      avatarsPanel.setBackgroundMode(SWT.INHERIT_FORCE);
      scrollable.setContent(avatarsPanel);

      scrollable.addListener(
          SWT.Resize,
          new Listener() {

            public void handleEvent(Event event) {
              Rectangle r = scrollable.getClientArea();
              scrollable.setMinHeight(avatarsPanel.computeSize(r.width, SWT.DEFAULT).y);
            }
          });

      /*
       * Specify avatar dimensions and attributes before creating the avatars
       */
      textColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
      selectedTextColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
      textLinkColor = properties.getColor("color.links.hover");
      imageBorderColor = properties.getColor("color.buddy.bg.border");
      selectedColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
      highlightedColor = parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);

      avatarHightLightBorder = 0;
      avatarImageBorder = 1;
      hSpacing = 1;
      avatarImageSize = new Point(40, 40);
      avatarNameSize = new Point(60, 30);
      avatarSize = new Point(0, 0);
      avatarSize.x =
          Math.max(avatarNameSize.x, avatarImageSize.x)
              + (2 * (avatarHightLightBorder + avatarImageBorder));
      avatarSize.y =
          avatarNameSize.y
              + avatarImageSize.y
              + (2 * (avatarHightLightBorder + avatarImageBorder) + 6);

      fillBuddies(avatarsPanel);

      /* UNCOMMENT THIS SECTION TO REVERT TO A ROW LAYOUT*/
      //			RowLayout rLayout = new RowLayout(SWT.HORIZONTAL);
      //			rLayout.wrap = true;
      //			rLayout.spacing = hSpacing;
      //			avatarsPanel.setLayout(rLayout);

      // COMMENT THIS SECTION TO REVERT TO A ROW LAYOUT
      SimpleReorderableListLayout rLayout = new SimpleReorderableListLayout();
      rLayout.margin = hSpacing;
      rLayout.wrap = true;
      rLayout.center = true;
      avatarsPanel.setLayout(rLayout);

      avatarsPanel.pack();

      avatarsPanel.addMouseListener(
          new MouseAdapter() {
            public void mouseDown(MouseEvent e) {
              select(null, false, false);
            }
          });

      avatarsPanel.addMouseListener(
          new MouseAdapter() {
            public void mouseDown(MouseEvent e) {
              select(null, false, false);
            }
          });

      parent.layout();

      hookFAQLink();

      hookImageAction();
    }

    return null;
  }

  public boolean isEditMode() {
    return isEditMode;
  }

  public void setEditMode(boolean value) {
    if (isEditMode != value) {
      isEditMode = value;
      for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
        AvatarWidget widget = (AvatarWidget) iterator.next();
        widget.refreshVisual();
      }

      if (true == value) {
        setShareMode(false, null);
        setAddBuddyMode(false);
      }
    }
  }

  private void fillBuddies(Composite composite) {

    List buddies = getBuddies();

    showNoBuddiesPanel(buddies.size() == 0);

    for (Iterator iterator = buddies.iterator(); iterator.hasNext(); ) {
      VuzeBuddySWT vuzeBuddy = (VuzeBuddySWT) iterator.next();
      createBuddyControls(composite, vuzeBuddy);
    }
    composite.layout();
    Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    composite.setSize(size);
  }

  private void showNoBuddiesPanel(boolean value) {
    if (soNoBuddies != null && soNoBuddies.isVisible() != value) {
      soNoBuddies.setVisible(value);
    }
  }

  private AvatarWidget createBuddyControls(Composite composite, final VuzeBuddySWT vuzeBuddy) {
    AvatarWidget avatarWidget =
        new AvatarWidget(this, avatarSize, avatarImageSize, avatarNameSize, vuzeBuddy);
    avatarWidget.setBorderWidth(avatarHightLightBorder);
    avatarWidget.setTextColor(textColor);
    avatarWidget.setSelectedTextColor(selectedTextColor);
    avatarWidget.setTextLinkColor(textLinkColor);
    avatarWidget.setImageBorderColor(imageBorderColor);
    avatarWidget.setImageBorder(avatarImageBorder);
    avatarWidget.setSelectedColor(selectedColor);
    avatarWidget.setHighlightedColor(highlightedColor);

    /* UNCOMMENT THIS SECTION TO REVERT TO A ROW LAYOUT*/
    //		RowData rData = new RowData();
    //		rData.width = avatarSize.x;
    //		rData.height = avatarSize.y;
    //		avatarWidget.getControl().setLayoutData(rData);

    // COMMENT THIS SECTION TO REVERT TO A ROW LAYOUT
    SimpleReorderableListLayoutData rData = new SimpleReorderableListLayoutData();
    rData.width = avatarSize.x;
    rData.height = avatarSize.y;
    rData.position = (int) VuzeBuddyManager.getBuddyPosition(vuzeBuddy);
    avatarWidget.getControl().setLayoutData(rData);

    avatarWidgets.add(avatarWidget);

    chat.checkBuddy(vuzeBuddy);

    return avatarWidget;
  }

  /**
   * Returns whether the given <code>AvatarWidget</code> is fully visible in the view port of the
   * viewer
   */
  public boolean isFullyVisible(AvatarWidget avatarWidget) {
    if (null != avatarWidget
        && null != avatarWidget.getControl()
        && false == avatarWidget.getControl().isDisposed()) {

      Rectangle controlBounds = avatarWidget.getControl().getBounds();
      if (controlBounds.x + controlBounds.width
          < avatarsPanel.getBounds().width - avatarsPanel.getBounds().x) {
        return true;
      }
    }
    return false;
  }

  public void removeBuddy(final AvatarWidget widget) {
    Utils.execSWTThreadLater(
        0,
        new AERunnable() {
          public void runSupport() {
            avatarWidgets.remove(widget);
            widget.dispose(
                true,
                new AvatarWidget.AfterDisposeListener() {
                  public void disposed() {
                    avatarsPanel.setSize(avatarsPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true));
                    if (avatarWidgets.size() < 1) {
                      showNoBuddiesPanel(true);
                    }
                  }
                });
          }
        });
  }

  public void removeBuddy(VuzeBuddy buddy) {
    AvatarWidget widget = findWidget(buddy);
    if (null != widget) {
      removeBuddy(widget);
    } else {
      Debug.out("Unknown VuzeBuddy; can not remove from viewer since we don't have it.");
    }
  }

  public void updateBuddy(final VuzeBuddy buddy) {
    if (buddy instanceof VuzeBuddySWT) {

      Utils.execSWTThreadLater(
          0,
          new AERunnable() {

            public void runSupport() {
              AvatarWidget widget = findWidget(buddy);
              if (null != widget) {
                widget.setVuzeBuddy((VuzeBuddySWT) buddy);
              } else {
                /*
                 * If not found yet then we create the avatar for it; this really should not happen
                 * but we'll handle it just in case
                 */
                addBuddy(buddy);
              }
            }
          });
    }
  }

  public void addBuddy(final VuzeBuddy buddy) {
    if (buddy instanceof VuzeBuddySWT) {
      Utils.execSWTThreadLater(
          0,
          new AERunnable() {
            public void runSupport() {
              AvatarWidget widget = findWidget(buddy);
              if (widget == null) {
                if (soNoBuddies != null) {
                  soNoBuddies.setVisible(false);
                }
                createBuddyControls(avatarsPanel, (VuzeBuddySWT) buddy);
                avatarsPanel.layout();
                Point size = avatarsPanel.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
                avatarsPanel.setSize(size);
              }
            }
          });

    } else {
      Debug.out("Wrong type VuzeBuddy... must be of type VuzeBuddySWT");
    }
  }

  private AvatarWidget findWidget(VuzeBuddy buddy) {
    if (null != buddy) {
      for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
        AvatarWidget widget = (AvatarWidget) iterator.next();
        if (null != widget.getVuzeBuddy()) {
          if (true == buddy.getLoginID().equals(widget.getVuzeBuddy().getLoginID())) {
            return widget;
          }
        }
      }
    }

    return null;
  }

  /**
   * Return a list of <code>VuzeBuddySWT</code> that are currently selected
   *
   * @return
   */
  public List getSelection() {
    List selected = new ArrayList();
    for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
      AvatarWidget widget = (AvatarWidget) iterator.next();
      if (true == widget.isSelected()) {
        selected.add(widget.getVuzeBuddy());
      }
    }
    return selected;
  }

  public void select(VuzeBuddySWT buddy, boolean value, boolean appendSelection) {

    if (null != buddy) {
      for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
        AvatarWidget widget = (AvatarWidget) iterator.next();
        if (true == buddy.equals(widget.getVuzeBuddy())) {
          widget.setSelected(value);
          if (true == appendSelection) {
            break;
          }
        } else if (false == appendSelection) {
          if (true == value) {
            if (widget.isSelected() != false) {
              widget.setSelected(false);
              widget.refreshVisual();
            }
          } else {
            widget.setSelected(false);
            widget.refreshVisual();
          }
        }
      }
    }
    /*
     * De-select all buddies if the given 'buddy' is null
     */
    else {
      for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
        AvatarWidget widget = (AvatarWidget) iterator.next();
        if (true == widget.isSelected()) {
          widget.setSelected(false);
          widget.refreshVisual();
        }
      }
    }
  }

  private void recomputeOrder(boolean delay) {

    if (delay) {

      synchronized (this) {
        if (reorder_outstanding) {

          return;
        }

        reorder_outstanding = true;

        new DelayedEvent(
            "BuddiesViewer:delayReorder",
            5 * 1000,
            new AERunnable() {
              public void runSupport() {
                synchronized (BuddiesViewer.this) {
                  reorder_outstanding = false;
                }

                recomputeOrder(false);
              }
            });

        return;
      }
    }

    Utils.execSWTThreadLater(
        0,
        new AERunnable() {
          public void runSupport() {

            /* UNCOMMENT THIS SECTION TO REVERT TO A ROW LAYOUT
            return;
            */

            // COMMENT THIS SECTION TO REVERT TO A ROW LAYOUT
            if (avatarsPanel.isDisposed()) return;

            final List buddies = VuzeBuddyManager.getAllVuzeBuddies();

            // Only sort by online status if we show it
            if (SHOW_ONLINE_STATUS) {
              Collections.sort(
                  buddies,
                  new Comparator() {
                    public int compare(Object o1, Object o2) {
                      VuzeBuddy v1 = (VuzeBuddy) o1;
                      VuzeBuddy v2 = (VuzeBuddy) o2;
                      int score = 0;
                      ChatDiscussion d1 = getChat().getChatDiscussionFor(v1);
                      ChatDiscussion d2 = getChat().getChatDiscussionFor(v2);
                      if (d1 != null && d1.getUnreadMessages() > 0) {
                        score -= 1;
                      }
                      if (d2 != null && d2.getUnreadMessages() > 0) {
                        score += 1;
                      }

                      if (score == 0) {
                        if (d1 != null && d1.getNbMessages() > 0) {
                          score -= 1;
                        }
                        if (d2 != null && d2.getNbMessages() > 0) {
                          score += 1;
                        }
                      }

                      if (score == 0) {
                        score -= v1.isOnline(true) ? 1 : 0;
                        score += v2.isOnline(true) ? 1 : 0;
                      }

                      return score;
                    }
                  });
            }

            boolean changed = false;
            for (int i = 0; i < buddies.size(); i++) {
              VuzeBuddy buddy = (VuzeBuddy) buddies.get(i);
              AvatarWidget widget = findWidget(buddy);
              if (widget != null) {
                Control control = widget.getControl();
                if (control != null && !control.isDisposed()) {
                  Object data = widget.getControl().getLayoutData();
                  if (data instanceof SimpleReorderableListLayoutData) {
                    SimpleReorderableListLayoutData rData =
                        (SimpleReorderableListLayoutData) widget.getControl().getLayoutData();
                    if (rData.position != i) {
                      rData.position = i;
                      changed = true;
                    }
                  }
                }
              }
            }
            if (changed) {
              avatarsPanel.layout();
            }
          }
        });
  }

  private List getBuddies() {

    /*
     * Add the listener only once at the beginning
     */
    if (null == buddiesList) {
      VuzeBuddyManager.addListener(
          new VuzeBuddyListener() {

            public void buddyRemoved(VuzeBuddy buddy) {
              removeBuddy(buddy);
              recomputeOrder(false);
            }

            public void buddyChanged(VuzeBuddy buddy) {
              updateBuddy(buddy);
              recomputeOrder(true);
            }

            public void buddyAdded(VuzeBuddy buddy, int position) {
              addBuddy(buddy);
              recomputeOrder(false);
            }

            public void buddyOrderChanged() {}
          },
          false);
    }

    buddiesList = VuzeBuddyManager.getAllVuzeBuddies();
    return buddiesList;
  }

  public Composite getControl() {
    return avatarsPanel;
  }

  public boolean isShareMode() {
    return isShareMode;
  }

  public void addAllToShare() {
    addToShare(avatarWidgets);
  }

  public void removeAllFromShare() {
    removeFromShare(avatarWidgets);
  }

  public void addToShare(List avatars) {

    for (Iterator iterator = avatars.iterator(); iterator.hasNext(); ) {
      Object object = (Object) iterator.next();
      if (object instanceof AvatarWidget) {
        addToShare((AvatarWidget) object);
      }
    }
  }

  public void addToShare(AvatarWidget widget) {
    /*if (null == sharePage) {
    	SkinView detailPanelView = SkinViewManager.getByClass(DetailPanel.class);
    	if (detailPanelView instanceof DetailPanel) {
    		DetailPanel detailPanel = ((DetailPanel) detailPanelView);
    		sharePage = (SharePage) detailPanel.getPage(SharePage.PAGE_ID);

    	} else {
    		throw new IllegalArgumentException(
    				"Oops.. looks like the DetailPanel skin is not properly initialized");
    	}
    }*/
    if (sharePage != null) {
      sharePage.addBuddy(widget.getVuzeBuddy());
    }
    widget.setSharedAlready(true);
  }

  public void removeFromShare(List avatars) {

    for (Iterator iterator = avatars.iterator(); iterator.hasNext(); ) {
      Object object = (Object) iterator.next();
      if (object instanceof AvatarWidget) {
        removeFromShare((AvatarWidget) object);
      }
    }
  }

  public void removeFromShare(AvatarWidget widget) {
    if (sharePage != null) {
      sharePage.removeBuddy(widget.getVuzeBuddy());
    }
    widget.setSharedAlready(false);
  }

  public void addToShare(VuzeBuddy buddy) {
    AvatarWidget widget = findWidget(buddy);
    if (null != widget) {
      if (false == widget.isSharedAlready()) {
        addToShare(widget);
      }
    }
  }

  public void addSelectionToShare() {

    for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
      AvatarWidget widget = (AvatarWidget) iterator.next();
      if (true == widget.isSelected()) {
        addToShare(widget);
      }
    }
  }

  public void removeFromShare(VuzeBuddy buddy) {

    if (null != buddy) {
      for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
        AvatarWidget widget = (AvatarWidget) iterator.next();
        if (null != widget.getVuzeBuddy()) {
          if (true == buddy.getLoginID().equals(widget.getVuzeBuddy().getLoginID())) {
            if (sharePage != null) {
              sharePage.removeBuddy(widget.getVuzeBuddy());
            }
            widget.setSharedAlready(false);
            break;
          }
        }
      }
    }
  }

  public void setShareMode(boolean isShareMode, SharePage sharePage) {

    this.sharePage = sharePage;

    if (this.isShareMode != isShareMode) {
      this.isShareMode = isShareMode;
      for (Iterator iterator = avatarWidgets.iterator(); iterator.hasNext(); ) {
        AvatarWidget widget = (AvatarWidget) iterator.next();
        if (false == isShareMode) {
          widget.setSharedAlready(false);
        }
        widget.refreshVisual();
      }

      if (true == isShareMode) {
        setEditMode(false);
        setAddBuddyMode(false);
      }
    }
  }

  public boolean isNonActiveMode() {
    return !isAddBuddyMode() && !isShareMode() && !isEditMode();
  }

  public boolean isAddBuddyMode() {
    return isAddBuddyMode;
  }

  public void setAddBuddyMode(boolean isAddBuddyMode) {
    this.isAddBuddyMode = isAddBuddyMode;
    /*
     * Turn off share mode when we enter add buddy flow
     */
    if (true == isAddBuddyMode) {
      setShareMode(false, null);
      setEditMode(false);
    }
  }

  public void setMode(int mode) {
    if (mode == none_active_mode) {
      setShareMode(false, null);
      setEditMode(false);
      setAddBuddyMode(false);
    } else if (mode == edit_mode) {
      setEditMode(true);
    } else if (mode == share_mode) {
      setShareMode(true, sharePage);
    } else if (mode == add_buddy_mode) {
      setAddBuddyMode(true);
    }

    if (mode == disabled_mode) {
      setEnabled(false);
    } else {
      setEnabled(true);
    }
  }

  public void hookFAQLink() {
    SWTSkinObject FAQObject = skin.getSkinObject("buddies-viewer-nobuddies-link");
    if (null != FAQObject) {
      SWTSkinButtonUtility FAQButton = new SWTSkinButtonUtility(FAQObject);
      FAQButton.addSelectionListener(
          new ButtonListenerAdapter() {
            public void pressed(
                SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
              String url = Constants.URL_FAQ_BY_TOPIC_ENTRY + FAQTopics.FAQ_TOPIC_WHAT_ARE_FRIENDS;
              Utils.launch(url);
            }
          });
    }
  }

  public void hookImageAction() {
    SWTSkinObject imageObject = skin.getSkinObject("buddies-viewer-nobuddies-graphic");
    if (null != imageObject) {
      SWTSkinButtonUtility imageButton = new SWTSkinButtonUtility(imageObject);
      imageButton.addSelectionListener(
          new ButtonListenerAdapter() {
            public void pressed(
                SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
              FriendsToolbar friendsToolbar =
                  (FriendsToolbar) SkinViewManager.getByClass(FriendsToolbar.class);
              if (friendsToolbar != null) {
                friendsToolbar.addBuddy();
              }
            }
          });
    }
  }

  public boolean isEnabled() {
    return isEnabled;
  }

  public void setEnabled(boolean isEnabled) {
    if (this.isEnabled != isEnabled) {
      this.isEnabled = isEnabled;
      avatarsPanel.setEnabled(isEnabled);
      avatarsPanel.layout(true);
    }
  }

  public Chat getChat() {
    return chat;
  }

  /**
   * @return
   * @since 3.1.1.1
   */
  public Color getColorFileDragBorder() {
    return colorFileDragBorder;
  }

  /**
   * @return
   * @since 3.1.1.1
   */
  public Color getColorFileDragBG() {
    return colorFileDragBG;
  }
}
示例#17
0
文件: FindTool.java 项目: URMC/i2b2
public class FindTool extends ApplicationWindow {
  private Log log = LogFactory.getLog(FindTool.class.getName());
  private NodeBrowser browser;
  private String findText = null;
  private String categoryKey;
  private String match;
  private Button findButton;
  private List categories;
  private StatusLineManager slm;
  public static final String OS = System.getProperty("os.name").toLowerCase();

  public FindTool(StatusLineManager slm) {
    super(null);
    this.slm = slm;
  }

  public Control getFindTabControl(TabFolder tabFolder) {
    // Find Composite
    Composite compositeFind = new Composite(tabFolder, SWT.NULL);
    GridLayout gridLayout = new GridLayout(2, false);
    compositeFind.setLayout(gridLayout);
    /*		GridData fromTreeGridData = new GridData (GridData.FILL_BOTH);
    		fromTreeGridData.grabExcessHorizontalSpace = true;
    		fromTreeGridData.grabExcessVerticalSpace = true;
    	//	fromTreeGridData.widthHint = 300;
    		compositeFind.setLayoutData(fromTreeGridData);
    */

    //	First Set up the match combo box
    final Combo matchCombo = new Combo(compositeFind, SWT.READ_ONLY);

    matchCombo.add("Starting with");
    matchCombo.add("Ending with");
    matchCombo.add("Containing");
    matchCombo.add("Exact");

    // set default category
    matchCombo.setText("Containing");
    match = "Containing";

    matchCombo.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            // Item in list has been selected
            match = matchCombo.getItem(matchCombo.getSelectionIndex());
          }

          public void widgetDefaultSelected(SelectionEvent e) {
            // this is not an option (text cant be entered)
          }
        });

    // Then set up the Find text combo box
    final Combo findCombo = new Combo(compositeFind, SWT.DROP_DOWN);
    GridData findComboData = new GridData(GridData.FILL_HORIZONTAL);
    findComboData.widthHint = 200;
    findComboData.horizontalSpan = 1;
    findCombo.setLayoutData(findComboData);
    findCombo.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            // Text Item has been entered
            // Does not require 'return' to be entered
            findText = findCombo.getText();
          }
        });

    findCombo.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {}

          public void widgetDefaultSelected(SelectionEvent e) {
            findText = findCombo.getText();
            if (findCombo.indexOf(findText) < 0) {
              findCombo.add(findText);
            }
            if (findButton.getText().equals("Find")) {
              slm.setMessage("Performing search");
              slm.update(true);
              browser.flush();
              ModifierComposite.getInstance().disableComposite();
              System.setProperty("statusMessage", "Calling WebService");

              TreeNode placeholder = new TreeNode(1, "placeholder", "working...", "C-UNDEF");
              browser.rootNode.addChild(placeholder);
              browser.refresh();

              browser.getFindData(categoryKey, categories, findText, match).start();
              findButton.setText("Cancel");

            } else {
              System.setProperty("statusMessage", "Canceling WebService call");
              browser.refresh();
              browser.stopRunning = true;
              findButton.setText("Find");
            }
          }
        });

    // Next include 'Find' Button
    findButton = new Button(compositeFind, SWT.PUSH);
    findButton.setText("Find");
    GridData findButtonData = new GridData();
    if (OS.startsWith("mac")) findButtonData.widthHint = 80;
    else findButtonData.widthHint = 60;
    findButton.setLayoutData(findButtonData);
    findButton.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent e) {
            // Add item to findCombo drop down list if not already there
            if (findText == null) {
              return;
            }
            if (findCombo.indexOf(findText) < 0) {
              findCombo.add(findText);
            }
            if (findButton.getText().equals("Find")) {
              ModifierComposite.getInstance().disableComposite();
              browser.flush();
              System.setProperty("statusMessage", "Calling WebService");
              TreeNode placeholder = new TreeNode(1, "placeholder", "working...", "C-UNDEF");
              browser.rootNode.addChild(placeholder);
              browser.refresh();

              browser.getFindData(categoryKey, categories, findText, match).start();
              findButton.setText("Cancel");
            } else {
              System.setProperty("statusMessage", "Canceling WebService call");
              browser.refresh();
              browser.stopRunning = true;
              findButton.setText("Find");
            }
          }
        });
    // Next set up the category combo box
    final Combo categoryCombo = new Combo(compositeFind, SWT.READ_ONLY);
    setCategories(categoryCombo);

    categoryCombo.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            // Item in list has been selected
            if (categoryCombo.getSelectionIndex() == 0) categoryKey = "any";
            else {
              ConceptType concept =
                  (ConceptType) categories.get(categoryCombo.getSelectionIndex() - 1);
              categoryKey = StringUtil.getTableCd(concept.getKey());
            }
          }

          public void widgetDefaultSelected(SelectionEvent e) {
            // this is not an option (text cant be entered)
          }
        });
    ModifierComposite.setInstance(compositeFind);
    browser = new NodeBrowser(compositeFind, 1, findButton, slm);

    return compositeFind;
  }

  private void setCategories(Combo categoryCombo) {
    // set default category for combo box
    categoryCombo.add("Any Category");
    categoryCombo.setText("Any Category");
    categoryKey = "any";

    categories = getCategories();

    if (categories != null) {
      Iterator categoriesIterator = categories.iterator();
      while (categoriesIterator.hasNext()) {
        ConceptType category = (ConceptType) categoriesIterator.next();
        String name = category.getName();
        categoryCombo.add(name);
      }
    }
    return;
  }

  public List getCategories() {
    List concepts = null;
    try {
      //		GetReturnType request = new GetReturnType();
      //		request.setType("limited");

      GetCategoriesType request = new GetCategoriesType();
      request.setType("core");
      request.setHiddens(false);
      request.setSynonyms(false);

      OntologyResponseMessage msg = new OntologyResponseMessage();
      StatusType procStatus = null;
      while (procStatus == null || !procStatus.getType().equals("DONE")) {
        String response = OntServiceDriver.getCategories(request, "FIND");
        procStatus = msg.processResult(response);
        //				if  other error codes
        //				TABLE_ACCESS_DENIED and USER_INVALID, DATABASE ERROR
        if (procStatus.getType().equals("ERROR")) {
          System.setProperty("errorMessage", procStatus.getValue());
          return concepts;
        }
        procStatus.setType("DONE");
      }
      ConceptsType allConcepts = msg.doReadConcepts();
      if (allConcepts != null) concepts = allConcepts.getConcept();

    } catch (AxisFault e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", "Ontology cell unavailable");
    } catch (I2B2Exception e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", e.getMessage());
    } catch (Exception e) {
      log.error(e.getMessage());
      System.setProperty("errorMessage", "Remote server unavailable");
    }

    return concepts;
  }
}