public Menu getMenu(Control parent) { if (menu != null) { menu.dispose(); menu = null; } for (Alias alias : SQLExplorerPlugin.getDefault().getAliasManager().getAliases()) for (User user : alias.getUsers()) { if (menu == null) menu = new Menu(parent); NewConnection action = new NewConnection(user); addActionToMenu(menu, action); } return menu; }
/** * Return the image used for the given node. * * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) */ @Override public Image getImage(Object element) { if (element instanceof Alias) { Alias alias = (Alias) element; for (User user : alias.getUsers()) if (!user.getSessions().isEmpty()) return _activeAliasImage; return _inactiveAliasImage; } else if (element instanceof ManagedDriver) { return _driverImage; } else if (element instanceof Query) return _queryImage; else if (element instanceof QueryParameter) return _queryParamImage; else if (element instanceof DriverManager) return _dbResImage; return _sessionImage; }
/** * Return the text to display * * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) */ @Override 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; } else if (element instanceof ManagedDriver) { return ((ManagedDriver) element).getId() + " driver: " + ((ManagedDriver) element).getDriverClassName(); } else if (element instanceof Query) { return ((Query) element).getName(); } else if (element instanceof QueryParameter) { return ((QueryParameter) element).getName(); } else if (element instanceof DriverManager) { return "DB Resources"; } return null; }