/**
   * Return the text to display
   *
   * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
   */
  public String getText(Object element) {
    if (element instanceof Alias) {
      Alias alias = (Alias) element;

      String label = alias.getName();
      int numSessions = 0;

      for (User user : alias.getUsers()) numSessions += user.getConnections().size();

      if (numSessions == 1)
        return label
            + " ("
            + numSessions
            + " "
            + Messages.getString("ConnectionsView.ConnectedAlias.single.Postfix")
            + ")";

      if (numSessions > 1)
        return label
            + " ("
            + numSessions
            + " "
            + Messages.getString("ConnectionsView.ConnectedAlias.multiple.Postfix")
            + ")";

      return label;

    } else if (element instanceof User) {
      User user = (User) element;
      return user.getUserName();

    } else if (element instanceof SQLConnection) {
      SQLConnection connection = (SQLConnection) element;
      String label;

      if (connection.getDescription() == null) {
        SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss");
        label =
            Messages.getString("ConnectionsView.ConnectedAlias.ConnectedSince")
                + ' '
                + fmt.format(new Date(connection.getCreatedTime()));
      } else
        label =
            Messages.getString("ConnectionsView.ConnectedAlias.Connection")
                + ' '
                + connection.getDescription();

      if (connection.isPooled())
        label += ' ' + Messages.getString("ConnectionsView.ConnectedAlias.Pooled");
      return label;
    }

    return null;
  }
  /** Set a default message, this method is called when no results are available for viewing. */
  private void setDefaultMessage() {

    clearParent();

    // add message
    String message = Messages.getString("SQLResultsView.NoResults");
    Label label = new Label(_parent, SWT.FILL);
    label.setText(message);
    label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    _parent.layout();
    _parent.redraw();
  }
  /**
   * Creates all the tabs in the detail pane to display the information for a given node.
   *
   * @param composite
   * @param node
   */
  public static void createTabs(Composite composite, INode node) {

    List<IDetailTab> tabs = getTabs(node);

    if (tabs == null || tabs.size() == 0) {
      // no detail found..

      Label label = new Label(composite, SWT.FILL);
      label.setText(
          Messages.getString("DatabaseDetailView.Tab.Unavailable") + " " + node.getLabelText());
      label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

      return;
    }

    // create tabs
    TabFolder tabFolder = new TabFolder(composite, SWT.NULL);

    // only init tabs when the tab becomes active
    tabFolder.addSelectionListener(
        new SelectionListener() {

          public void widgetDefaultSelected(SelectionEvent e) {

            // noop
          }

          public void widgetSelected(SelectionEvent e) {

            TabItem tabItem = (TabItem) e.item;
            IDetailTab tab = (IDetailTab) tabItem.getData();
            if (tab != null) {

              // create composite on tab and fill it..
              Composite detailComposite = new Composite(tabItem.getParent(), SWT.FILL);
              tabItem.setControl(detailComposite);
              detailComposite.setLayout(new FillLayout());
              tab.fillComposite(detailComposite);
              detailComposite.layout();

              // store tab name, so we can reselect when other node is
              // chosen
              DetailTabManager.setActiveTabName(tabItem.getText());
            }
          }
        });

    // add tabs to folder
    int tabIndex = 0;
    for (IDetailTab detailTab : tabs) {

      // create tab
      TabItem tabItem = new TabItem(tabFolder, SWT.NULL);
      tabItem.setText(detailTab.getLabelText());
      tabItem.setToolTipText(detailTab.getLabelToolTipText());

      // store tab so we can fill later
      tabItem.setData(detailTab);

      // reselect same tab as was previous selected
      if (tabItem.getText() != null && _activeTabName != null) {
        if (tabItem.getText().equals(_activeTabName)) {
          tabFolder.setSelection(tabIndex);
        }
      }

      tabIndex++;
    }

    // load data for active tab, default to first one if none is selected
    tabIndex = tabFolder.getSelectionIndex();
    if (tabIndex == -1) {
      tabIndex = 0;
    }

    TabItem tabItem = tabFolder.getItem(tabIndex);
    if (tabItem != null) {
      Composite detailComposite = new Composite(tabItem.getParent(), SWT.FILL);
      tabItem.setControl(detailComposite);
      detailComposite.setLayout(new FillLayout());
      IDetailTab tab = (IDetailTab) tabItem.getData();
      tab.fillComposite(detailComposite);
      detailComposite.layout();
    }

    tabFolder.layout();
  }
Example #4
0
 public String getStatusMessage() {
   return Messages.getString("DatabaseDetailView.Tab.Indexes.status")
       + " "
       + getNode().getQualifiedName();
 }
Example #5
0
 public String getLabelText() {
   return Messages.getString("DatabaseDetailView.Tab.Indexes");
 }
Example #6
0
/** @author Davy Vanherbergen */
public class IndexesTab extends AbstractDataSetTab {

  private static final String COLUMN_LABELS[] = {
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.IsNonUnique"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.IndexQualifier"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.SimpleName"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.IndexType"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.OrdinalPosition"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.ColumnName"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.SortOrder"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.Cardinality"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.Pages"),
    Messages.getString("DatabaseDetailView.Tab.Indexes.Col.FilterCondition")
  };

  public String getLabelText() {
    return Messages.getString("DatabaseDetailView.Tab.Indexes");
  }

  public DataSet getDataSet() throws Exception {

    INode node = getNode();

    if (node == null) {
      return null;
    }

    if (node instanceof TableNode) {
      TableNode tableNode = (TableNode) node;

      List<IndexInfo> indexes =
          node.getSession().getMetaData().getIndexInfo(tableNode.getTableInfo());
      Comparable<?>[][] dataRows = new Comparable[indexes.size()][];
      int index = 0;
      for (IndexInfo col : indexes) {
        Comparable<?>[] row = new Comparable[COLUMN_LABELS.length];
        dataRows[index++] = row;

        int i = 0;
        row[i++] = col.isNonUnique();
        row[i++] = col.getIndexQualifier();
        row[i++] = col.getSimpleName();
        row[i++] = col.getIndexType();
        row[i++] = col.getOrdinalPosition();
        row[i++] = col.getColumnName();
        row[i++] = col.getSortOrder();
        row[i++] = col.getCardinality();
        row[i++] = col.getPages();
        row[i++] = col.getFilterCondition();
        if (i != COLUMN_LABELS.length)
          throw new RuntimeException("Internal error: ColumnInfoTab: wrong number of columns");
      }
      DataSet dataSet = new DataSet(COLUMN_LABELS, dataRows);

      return dataSet;
    }

    return null;
  }

  public String getStatusMessage() {
    return Messages.getString("DatabaseDetailView.Tab.Indexes.status")
        + " "
        + getNode().getQualifiedName();
  }
}