示例#1
0
  /** Load the data of the selected parameter into the table */
  private void list_selected() {
    String key;
    try {
      key = getCurrentKey();
    } catch (Exception e1) {
      return;
    }
    MeasurementHistoryController hist = master.getHistoryController();
    MeasurementHistory data;
    try {
      if (getCurrentTimeBase().equals("hours")) data = hist.getDataHours().get(key);
      else data = hist.getDataDays().get(key);
    } catch (Exception ex) {
      return;
    }

    Vector<MeasurementHistoryEntry> newData =
        new Vector<MeasurementHistoryEntry>(data.getValues().size());
    newData.addAll(data.getValues());

    Collections.sort(newData);
    Collections.reverse(newData);
    dataTable.removeAll();

    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);

    for (MeasurementHistoryEntry e : newData) {
      TableItem item = new TableItem(dataTable, SWT.NONE);
      item.setText(new String[] {sdf.format(e.getTimestamp()), "" + e.getValue()});
    }
  }
 protected void selectionChanged() {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     // Refresh Mappings Table
     fMappingsTable.removeAll();
     Vector Mappings = ((IdMap) items[0].getData()).getMappings();
     for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
       newMappingsTableItem((Mapping) enumeration.nextElement(), false);
     }
     // Refresh Ordered Table
     fOrderedTable.removeAll();
     ArrayList Ordered = ((IdMap) items[0].getData()).getOrdered();
     if (Ordered != null) {
       for (Iterator iter_ordered = Ordered.iterator(); iter_ordered.hasNext(); ) {
         newOrderedTableItem((Mapping) iter_ordered.next(), false);
       }
     }
   }
   updateEnabledState();
 }
  @Override
  protected void performDefaults() {
    typeTable.removeAll();
    colorPicker.removeAll();
    for (DBPConnectionType source : DataSourceProviderRegistry.getInstance().getConnectionTypes()) {
      addTypeToTable(source, new DBPConnectionType(source));
    }
    typeTable.select(0);
    if (selectedType != null) {
      for (int i = 0; i < typeTable.getItemCount(); i++) {
        if (typeTable.getItem(i).getData().equals(selectedType)) {
          typeTable.select(i);
          break;
        }
      }
    }
    // Ad predefined colors
    int[] colorList = {
      SWT.COLOR_WHITE,
      SWT.COLOR_BLACK,
      SWT.COLOR_RED,
      SWT.COLOR_DARK_RED,
      SWT.COLOR_GREEN,
      SWT.COLOR_DARK_GREEN,
      SWT.COLOR_YELLOW,
      SWT.COLOR_DARK_YELLOW,
      SWT.COLOR_BLUE,
      SWT.COLOR_DARK_BLUE,
      SWT.COLOR_MAGENTA,
      SWT.COLOR_DARK_MAGENTA,
      SWT.COLOR_CYAN,
      SWT.COLOR_DARK_CYAN,
      SWT.COLOR_GRAY,
      SWT.COLOR_DARK_GRAY
    };
    for (int colorCode : colorList) {
      Color color = colorPicker.getShell().getDisplay().getSystemColor(colorCode);
      colorPicker.add(null, COLOR_TEXT, color, color);
    }
    showSelectedType(getSelectedType());

    typeTable.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlResized(ControlEvent e) {
            UIUtils.packColumns(typeTable, true);
          }
        });
    super.performDefaults();
  }
  private void listRoles() {
    // clear table.
    userRolesTable.removeAll();

    UserManagerUtils.getInstance()
        .init(
            serverUrlText.getText().trim(),
            userNameText.getText().trim(),
            passwordText.getText().trim());

    String filter;
    if (StringUtils.isNotBlank(roleNamePatternText.getText())) {
      filter = roleNamePatternText.getText().trim();
    } else {
      filter = "*";
    }

    List<String> roles;
    try {
      roles = UserManagerUtils.getInstance().getRoles(filter, 1000);
    } catch (Exception e) {
      // If the server connection fails due to connectivity issues or invalid credentials, showing
      // an error message
      MessageBox msg = new MessageBox(getShell(), SWT.ICON_ERROR);
      msg.setMessage(SecurityFormMessageConstants.SERVER_CONNECTION_FAILURE_MESSAGE);
      msg.open();
      return;
    }

    for (final String role : roles) {
      if (!role.equals("false")) {
        TableItem item = new TableItem(userRolesTable, SWT.RIGHT);
        item.setText(new String[] {role, role});
        if (selectedRoles.contains(role)) {
          item.setChecked(true);
        }
      }
    }

    userRolesTable.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            updateSelectedRolesFromServer(event);
          }
        });
  }
示例#5
0
 public void removeAll() {
   // remove all items from the real storage first
   scanningResults.clear();
   super.removeAll();
   setSortColumn(null);
 }
  private void openFile(String fileName, Table table) {
    String outStr;
    try {

      CSVReader reader = new CSVReader(new FileReader(fileName), ',', '"');
      String[] strLineArr;

      // Open the file that is the first
      // command line parameter
      FileInputStream fstream = new FileInputStream(fileName);
      // Get the object of DataInputStream
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;

      table.clearAll();
      table.removeAll();
      table.redraw();

      int length = 0;
      boolean first = true;
      // Read File Line By Line
      while ((strLineArr = reader.readNext()) != null) {
        // while ((strLine = br.readLine()) != null)   {
        // Print the content on the console
        // outStr = strLine;
        TableItem item = null;

        if (first) {
          length = strLineArr.length;
        } else {
          item = new TableItem(table, SWT.NONE);
        }

        int thisLen = strLineArr.length;
        if (thisLen <= length) {
          // String[] line = new String[length];
          for (int i = 0; i < thisLen; i++) {
            // line[i] = st.nextToken();
            // item.setText (i, st.nextToken());
            if (first) {
              TableColumn column = new TableColumn(table, SWT.NONE);
              column.setText(strLineArr[i]);
            } else {

              // System.out.println("-- "+i+" -- " + strLineArr[i]);
              item.setText(i, strLineArr[i]);
            }
          }
        }
        first = false;
      }

      // System.out.println("Finisehd file");

      for (int i = 0; i < length; i++) {
        table.getColumn(i).pack();
      }
      // System.out.println("finished packing");
      // Close the input stream
      in.close();
    } catch (Exception e) { // Catch exception if any
      System.err.println("Error: " + e.getMessage());
      e.printStackTrace();
    }
  }