예제 #1
0
 public void setObjectValues() {
   ((JTextField) (fields.get("board"))).setText(sketch.getBoard().getName());
   ((JTextField) (fields.get("core"))).setText(sketch.getCore().getName());
   ((JTextField) (fields.get("compiler"))).setText(sketch.getCompiler().getName());
   ((JTextField) (fields.get("port"))).setText(sketch.getDevice().toString());
   ((JTextField) (fields.get("programmer"))).setText(sketch.getProgrammer());
 }
예제 #2
0
  public void save() {
    for (String key : fields.keySet()) {
      JComponent comp = fields.get(key);

      if (comp instanceof JTextField) {
        JTextField c = (JTextField) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      } else if (comp instanceof JTextArea) {
        JTextArea c = (JTextArea) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      }
    }

    sketch.saveConfig();
  }
예제 #3
0
    /** Displays the labels and the values for the panel. */
    protected void displayPnlFields(HashMap hmPnl) {
      if (hmPnl == null || hmPnl.isEmpty()) return;

      Iterator keySetItr = hmPnl.keySet().iterator();
      String strLabel = "";
      String strValue = "";

      // if the file is empty, then create an empty set of textfields.
      if (hmPnl == null || hmPnl.isEmpty()) {
        displayNewTxf("", "");
        return;
      }

      Container container = getParent();
      if (container != null) container.setVisible(false);
      try {
        // Get each set of label and value, and display them.
        while (keySetItr.hasNext()) {
          strLabel = (String) keySetItr.next();
          strValue = (String) hmPnl.get(strLabel);

          displayNewTxf(strLabel, strValue);
        }

        if (container != null) container.setVisible(true);
        revalidate();
        repaint();
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }
예제 #4
0
 public void actionPerformed(ActionEvent e) {
   HashMap data = getData(tree, selected_node);
   if (data != null) {
   } else {
     clearTable();
     data = new HashMap();
     data.put("Add Key", "Add Value");
   }
   populateTable(data);
   getContentPane().add(tablePanel, BorderLayout.SOUTH);
   validate();
 }
예제 #5
0
    HashMap getData(ReplicatedTree tree, String fqn) {
      HashMap data;
      Set keys;
      String key;
      Object value;

      if (tree == null || fqn == null) return null;
      keys = tree.getKeys(fqn);
      if (keys == null) return null;
      data = new HashMap();
      for (Iterator it = keys.iterator(); it.hasNext(); ) {
        key = (String) it.next();
        value = tree.get(fqn, key);
        if (value != null) data.put(key, value);
      }
      return data;
    }
예제 #6
0
 void addTextField(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextField field = new JTextField();
   field.setText(sketch.configFile.get(key));
   field.setMaximumSize(new Dimension(Integer.MAX_VALUE, field.getPreferredSize().height));
   fields.put(key, field);
   panel.add(field);
 }
예제 #7
0
    void populateTable(HashMap data) {
      String key, strval = "<null>";
      Object val;
      int num_rows = 0;
      Map.Entry entry;

      if (data == null) return;
      num_rows = data.size();
      clearTable();

      if (num_rows > 0) {
        for (Iterator it = data.entrySet().iterator(); it.hasNext(); ) {
          entry = (Map.Entry) it.next();
          key = (String) entry.getKey();
          val = entry.getValue();
          if (val != null) strval = val.toString();
          table_model.addRow(new Object[] {key, strval});
        }
        table_model.fireTableRowsInserted(0, num_rows - 1);
        validate();
      }
    }
예제 #8
0
 void addTextArea(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextArea field = new JTextArea();
   field.setText(sketch.configFile.get(key));
   field.setLineWrap(true);
   field.setWrapStyleWord(true);
   fields.put(key, field);
   JScrollPane scroll = new JScrollPane(field);
   scroll.setAlignmentX(0.0f);
   panel.add(scroll);
 }
  /**
   * Construct a "simplified name" based on the subject DN from the certificate. The purpose is to
   * have something shorter to display in the list. The name used is one of the following DN parts,
   * if available, otherwise the complete DN: 'CN', 'OU' or else 'O'.
   *
   * @param cert to read subject DN from
   * @return the simplified name
   */
  private static String getSimplifiedName(X509Certificate cert) {
    final HashMap<String, String> parts = new HashMap<String, String>();
    try {
      for (Rdn name : new LdapName(cert.getSubjectX500Principal().getName()).getRdns()) {
        if (name.getType() != null && name.getValue() != null) {
          parts.put(name.getType(), name.getValue().toString());
        }
      }
    } catch (InvalidNameException ignored) // NOPMD
    {
    }

    String result = parts.get("CN");
    if (result == null) {
      result = parts.get("OU");
    }
    if (result == null) {
      result = parts.get("O");
    }
    if (result == null) {
      result = cert.getSubjectX500Principal().getName();
    }
    return result;
  }
예제 #10
0
  /**
   * Helper function to display a Swing window with a tree representation of the specified list of
   * joins. See {@link #orderJoins}, which may want to call this when the analyze flag is true.
   *
   * @param js the join plan to visualize
   * @param pc the PlanCache accumulated whild building the optimal plan
   * @param stats table statistics for base tables
   * @param selectivities the selectivities of the filters over each of the tables (where tables are
   *     indentified by their alias or name if no alias is given)
   */
  private void printJoins(
      Vector<LogicalJoinNode> js,
      PlanCache pc,
      HashMap<String, TableStats> stats,
      HashMap<String, Double> selectivities) {

    JFrame f = new JFrame("Join Plan for " + p.getQuery());

    // Set the default close operation for the window,
    // or else the program won't exit when clicking close button
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    f.setVisible(true);

    f.setSize(300, 500);

    HashMap<String, DefaultMutableTreeNode> m = new HashMap<String, DefaultMutableTreeNode>();

    // int numTabs = 0;

    // int k;
    DefaultMutableTreeNode root = null, treetop = null;
    HashSet<LogicalJoinNode> pathSoFar = new HashSet<LogicalJoinNode>();
    boolean neither;

    System.out.println(js);
    for (LogicalJoinNode j : js) {
      pathSoFar.add(j);
      System.out.println("PATH SO FAR = " + pathSoFar);

      String table1Name = Database.getCatalog().getTableName(this.p.getTableId(j.t1Alias));
      String table2Name = Database.getCatalog().getTableName(this.p.getTableId(j.t2Alias));

      // Double c = pc.getCost(pathSoFar);
      neither = true;

      root =
          new DefaultMutableTreeNode(
              "Join "
                  + j
                  + " (Cost ="
                  + pc.getCost(pathSoFar)
                  + ", card = "
                  + pc.getCard(pathSoFar)
                  + ")");
      DefaultMutableTreeNode n = m.get(j.t1Alias);
      if (n == null) { // never seen this table before
        n =
            new DefaultMutableTreeNode(
                j.t1Alias
                    + " (Cost = "
                    + stats.get(table1Name).estimateScanCost()
                    + ", card = "
                    + stats.get(table1Name).estimateTableCardinality(selectivities.get(j.t1Alias))
                    + ")");
        root.add(n);
      } else {
        // make left child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t1Alias, root);

      n = m.get(j.t2Alias);
      if (n == null) { // never seen this table before

        n =
            new DefaultMutableTreeNode(
                j.t2Alias == null
                    ? "Subplan"
                    : (j.t2Alias
                        + " (Cost = "
                        + stats.get(table2Name).estimateScanCost()
                        + ", card = "
                        + stats
                            .get(table2Name)
                            .estimateTableCardinality(selectivities.get(j.t2Alias))
                        + ")"));
        root.add(n);
      } else {
        // make right child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t2Alias, root);

      // unless this table doesn't join with other tables,
      // all tables are accessed from root
      if (!neither) {
        for (String key : m.keySet()) {
          m.put(key, root);
        }
      }

      treetop = root;
    }

    JTree tree = new JTree(treetop);
    JScrollPane treeView = new JScrollPane(tree);

    tree.setShowsRootHandles(true);

    // Set the icon for leaf nodes.
    ImageIcon leafIcon = new ImageIcon("join.jpg");
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(leafIcon);
    renderer.setClosedIcon(leafIcon);

    tree.setCellRenderer(renderer);

    f.setSize(300, 500);

    f.add(treeView);
    for (int i = 0; i < tree.getRowCount(); i++) {
      tree.expandRow(i);
    }

    if (js.size() == 0) {
      f.add(new JLabel("No joins in plan."));
    }

    f.pack();
  }
예제 #11
0
  /**
   * This is a helper method that computes the cost and cardinality of joining joinToRemove to
   * joinSet (joinSet should contain joinToRemove), given that all of the subsets of size
   * joinSet.size() - 1 have already been computed and stored in PlanCache pc.
   *
   * @param stats table stats for all of the tables, referenced by table names rather than alias
   *     (see {@link #orderJoins})
   * @param filterSelectivities the selectivities of the filters over each of the tables (where
   *     tables are indentified by their alias or name if no alias is given)
   * @param joinToRemove the join to remove from joinSet
   * @param joinSet the set of joins being considered
   * @param bestCostSoFar the best way to join joinSet so far (minimum of previous invocations of
   *     computeCostAndCardOfSubplan for this joinSet, from returned CostCard)
   * @param pc the PlanCache for this join; should have subplans for all plans of size
   *     joinSet.size()-1
   * @return A {@link CostCard} objects desribing the cost, cardinality, optimal subplan
   * @throws ParsingException when stats, filterSelectivities, or pc object is missing tables
   *     involved in join
   */
  @SuppressWarnings("unchecked")
  private CostCard computeCostAndCardOfSubplan(
      HashMap<String, TableStats> stats,
      HashMap<String, Double> filterSelectivities,
      LogicalJoinNode joinToRemove,
      Set<LogicalJoinNode> joinSet,
      double bestCostSoFar,
      PlanCache pc)
      throws ParsingException {

    LogicalJoinNode j = joinToRemove;

    Vector<LogicalJoinNode> prevBest;

    if (this.p.getTableId(j.t1Alias) == null)
      throw new ParsingException("Unknown table " + j.t1Alias);
    if (this.p.getTableId(j.t2Alias) == null)
      throw new ParsingException("Unknown table " + j.t2Alias);

    String table1Name = Database.getCatalog().getTableName(this.p.getTableId(j.t1Alias));
    String table2Name = Database.getCatalog().getTableName(this.p.getTableId(j.t2Alias));
    String table1Alias = j.t1Alias;
    String table2Alias = j.t2Alias;

    Set<LogicalJoinNode> news = (Set<LogicalJoinNode>) ((HashSet<LogicalJoinNode>) joinSet).clone();
    news.remove(j);

    double t1cost, t2cost;
    int t1card, t2card;
    boolean leftPkey, rightPkey;

    if (news.isEmpty()) { // base case -- both are base relations
      prevBest = new Vector<LogicalJoinNode>();
      t1cost = stats.get(table1Name).estimateScanCost();
      t1card = stats.get(table1Name).estimateTableCardinality(filterSelectivities.get(j.t1Alias));
      leftPkey = isPkey(j.t1Alias, j.f1PureName);

      t2cost = table2Alias == null ? 0 : stats.get(table2Name).estimateScanCost();
      t2card =
          table2Alias == null
              ? 0
              : stats.get(table2Name).estimateTableCardinality(filterSelectivities.get(j.t2Alias));
      rightPkey = table2Alias == null ? false : isPkey(table2Alias, j.f2PureName);
    } else {
      // news is not empty -- figure best way to join j to news
      prevBest = pc.getOrder(news);

      // possible that we have not cached an answer, if subset
      // includes a cross product
      if (prevBest == null) {
        return null;
      }

      double prevBestCost = pc.getCost(news);
      int bestCard = pc.getCard(news);

      // estimate cost of right subtree
      if (doesJoin(prevBest, table1Alias)) { // j.t1 is in prevBest
        t1cost = prevBestCost; // left side just has cost of whatever
        // left
        // subtree is
        t1card = bestCard;
        leftPkey = hasPkey(prevBest);

        t2cost = j.t2Alias == null ? 0 : stats.get(table2Name).estimateScanCost();
        t2card =
            j.t2Alias == null
                ? 0
                : stats
                    .get(table2Name)
                    .estimateTableCardinality(filterSelectivities.get(j.t2Alias));
        rightPkey = j.t2Alias == null ? false : isPkey(j.t2Alias, j.f2PureName);
      } else if (doesJoin(prevBest, j.t2Alias)) { // j.t2 is in prevbest
        // (both
        // shouldn't be)
        t2cost = prevBestCost; // left side just has cost of whatever
        // left
        // subtree is
        t2card = bestCard;
        rightPkey = hasPkey(prevBest);

        t1cost = stats.get(table1Name).estimateScanCost();
        t1card = stats.get(table1Name).estimateTableCardinality(filterSelectivities.get(j.t1Alias));
        leftPkey = isPkey(j.t1Alias, j.f1PureName);

      } else {
        // don't consider this plan if one of j.t1 or j.t2
        // isn't a table joined in prevBest (cross product)
        return null;
      }
    }

    // case where prevbest is left
    double cost1 = estimateJoinCost(j, t1card, t2card, t1cost, t2cost);

    LogicalJoinNode j2 = j.swapInnerOuter();
    double cost2 = estimateJoinCost(j2, t2card, t1card, t2cost, t1cost);
    if (cost2 < cost1) {
      boolean tmp;
      j = j2;
      cost1 = cost2;
      tmp = rightPkey;
      rightPkey = leftPkey;
      leftPkey = tmp;
    }
    if (cost1 >= bestCostSoFar) return null;

    CostCard cc = new CostCard();

    cc.card = estimateJoinCardinality(j, t1card, t2card, leftPkey, rightPkey, stats);
    cc.cost = cost1;
    cc.plan = (Vector<LogicalJoinNode>) prevBest.clone();
    cc.plan.addElement(j); // prevbest is left -- add new join to end
    return cc;
  }
예제 #12
0
 public static String getInfo(String item) {
   return pluginInfo.get(item);
 }
예제 #13
0
    /** Reads the file, and sets the label and the values in the hashmap. */
    protected void setHM(String strPath, HashMap hmPnl) {
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      boolean bFileEmpty = true;
      boolean bPart11Pnl = isPart11Pnl();
      boolean bDefaultFile = isDefaultFile();

      // if the file is empty, then create an empty set of textfields.
      if (reader == null) {
        // displayNewTxf("","");
        return;
      }

      String strLine = null;
      StringTokenizer strTok;

      try {
        // read the file, and create a new set of textfields,
        // with the values from the file.
        while ((strLine = reader.readLine()) != null) {
          String strLabel = "";
          String strValue = "";
          bFileEmpty = false;

          if (strLine.startsWith("#")
              || strLine.startsWith("@")
              || strLine.startsWith("%")
              || strLine.startsWith("\"@")) continue;

          if (strLine.startsWith("\"")) strTok = new StringTokenizer(strLine, "\"");
          else strTok = new StringTokenizer(strLine, File.pathSeparator + ",\n");

          if (!strTok.hasMoreTokens()) continue;

          strLabel = strTok.nextToken();

          // the format for the part11 Default file is a little different
          // only parse out the part11Dir, and don't display other defaults
          if (bPart11Pnl && bDefaultFile) {
            if (!strLabel.equalsIgnoreCase("part11Dir")) continue;
          }

          if (strTok.hasMoreTokens()) {
            while (strTok.hasMoreTokens()) {
              strValue += strTok.nextToken();
              if (strTok.hasMoreTokens()) strValue += " ";
            }
          }

          // append "/data/$name" to part11Dir
          if (bPart11Pnl && bDefaultFile && strLabel.equalsIgnoreCase("part11Dir")) {
            StringBuffer sbDir = new StringBuffer(strValue);
            if (sbDir.lastIndexOf(File.separator) < sbDir.length() - 1)
              sbDir.append(File.separator);
            sbDir.append("data" + File.separator + "$");
            sbDir.append(WGlobal.NAME);
            strValue = sbDir.toString();
          }

          // displayNewTxf(strLabel, strValue);
          if (strLabel != null && strLabel.trim().length() > 0) hmPnl.put(strLabel, strValue);
        }
        reader.close();
      } catch (Exception e) {
        Messages.writeStackTrace(e);
        // e.printStackTrace();
        Messages.postDebug(e.toString());
      }
    }