List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:org.apache.directory.studio.ldapservers.actions.PropertiesAction.java
License:Apache License
/** * {@inheritDoc}/* w w w . j a va 2 s . c om*/ */ public void run() { if (view != null) { StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection(); if (!selection.isEmpty()) { LdapServer server = (LdapServer) selection.getFirstElement(); PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(view.getViewSite().getShell(), server, LdapServersPluginConstants.PROP_SERVER_PROPERTY_PAGE, null, null); dialog.getShell().setText(NLS.bind(Messages.getString("PropertiesAction.PropertiesFor"), //$NON-NLS-1$ shorten(server.getName(), 30))); dialog.open(); } } }
From source file:org.apache.directory.studio.ldapservers.actions.StartAction.java
License:Apache License
/** * {@inheritDoc}// ww w .ja v a 2s .c o m */ public void run() { if (view != null) { // Getting the selection StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { // Getting the server LdapServer server = (LdapServer) selection.getFirstElement(); LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension(); if ((ldapServerAdapterExtension != null) && (ldapServerAdapterExtension.getInstance() != null)) { LdapServerAdapter ldapServerAdapter = ldapServerAdapterExtension.getInstance(); try { // Getting the ports already in use String[] portsAlreadyInUse = ldapServerAdapter.checkPortsBeforeServerStart(server); if ((portsAlreadyInUse == null) || (portsAlreadyInUse.length > 0)) { String title = null; String message = null; if (portsAlreadyInUse.length == 1) { title = Messages.getString("StartAction.PortInUse"); //$NON-NLS-1$ message = NLS.bind(Messages.getString("StartAction.PortOfProtocolInUse"), //$NON-NLS-1$ new String[] { portsAlreadyInUse[0] }); } else { title = Messages.getString("StartAction.PortsInUse"); //$NON-NLS-1$ message = Messages.getString("StartAction.PortsOfProtocolsInUse"); //$NON-NLS-1$ for (String portAlreadyInUse : portsAlreadyInUse) { message += "\n - " + portAlreadyInUse; //$NON-NLS-1$ } } message += "\n\n" + Messages.getString("StartAction.Continue"); //$NON-NLS-1$ //$NON-NLS-2$ MessageDialog dialog = new MessageDialog(view.getSite().getShell(), title, null, message, MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, MessageDialog.OK); if (dialog.open() == MessageDialog.CANCEL) { return; } } // Creating and scheduling the job to start the server StudioLdapServerJob job = new StudioLdapServerJob(new StartLdapServerRunnable(server)); job.schedule(); } catch (Exception e) { // Showing an error in case no LDAP Server Adapter can be found MessageDialog.openError(view.getSite().getShell(), Messages.getString("StartAction.ErrorStartingServer"), //$NON-NLS-1$ NLS.bind( Messages.getString("StartAction.ServerCanNotBeStarted") + "\n" //$NON-NLS-1$//$NON-NLS-2$ + Messages.getString("StartAction.Cause"), //$NON-NLS-1$ server.getName(), e.getMessage())); } } else { // Showing an error in case no LDAP Server Adapter can be found MessageDialog.openError(view.getSite().getShell(), Messages.getString("StartAction.NoLdapServerAdapter"), //$NON-NLS-1$ NLS.bind(Messages.getString("StartAction.ServerCanNotBeStarted") + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + Messages.getString("StartAction.NoLdapServerAdapterCouldBeFound"), //$NON-NLS-1$ server.getName())); } } } }
From source file:org.apache.directory.studio.ldapservers.actions.StopAction.java
License:Apache License
/** * {@inheritDoc}/*from ww w . j a va 2s . c om*/ */ public void run() { if (view != null) { // Getting the selection StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { // Getting the server LdapServer server = (LdapServer) selection.getFirstElement(); // Creating and scheduling the job to stop the server StudioLdapServerJob job = new StudioLdapServerJob(new StopLdapServerRunnable(server)); job.schedule(); } } }
From source file:org.apache.directory.studio.ldapservers.apacheds.CreateConnectionAction.java
License:Apache License
/** * {@inheritDoc}//w ww . ja va 2 s . co m */ public void run(IAction action) { if (view != null) { // Getting the selection StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { // Getting the server LdapServer server = (LdapServer) selection.getFirstElement(); // Checking that the server is really an ApacheDS 2.0.0 server if (!ExtensionUtils.verifyApacheDs200OrPrintError(server, view)) { return; } // Parsing the 'config.ldif' file ConfigBean configuration = null; try { configuration = ApacheDS200LdapServerAdapter.getServerConfiguration(server).getConfigBean(); } catch (Exception e) { String message = Messages.getString("CreateConnectionAction.UnableReadServerConfiguration") //$NON-NLS-1$ + "\n\n" //$NON-NLS-1$ + Messages.getString("CreateConnectionAction.FollowingErrorOccurred") + e.getMessage(); //$NON-NLS-1$ reportErrorReadingServerConfiguration(view, message); return; } // Checking if we could read the 'server.xml' file if (configuration == null) { reportErrorReadingServerConfiguration(view, Messages.getString("CreateConnectionAction.UnableReadServerConfiguration")); //$NON-NLS-1$ return; } // Checking is LDAP and/or LDAPS is/are enabled if ((ApacheDS200LdapServerAdapter.isEnableLdap(configuration)) || (ApacheDS200LdapServerAdapter.isEnableLdaps(configuration))) { // Creating the connection using the helper class createConnection(server, configuration); } else { // LDAP and LDAPS protocols are disabled, we report this error to the user MessageDialog dialog = new MessageDialog(view.getSite().getShell(), Messages.getString("CreateConnectionAction.UnableCreateConnection"), null, //$NON-NLS-1$ Messages.getString("CreateConnectionAction.LDAPAndLDAPSDisabled"), MessageDialog.ERROR, //$NON-NLS-1$ new String[] { IDialogConstants.OK_LABEL }, MessageDialog.OK); dialog.open(); } } } }
From source file:org.apache.directory.studio.ldapservers.apacheds.RepairAction.java
License:Apache License
private LdapServer getSelectedServer() { if (view != null) { // Getting the selection StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { // Getting the server LdapServer server = (LdapServer) selection.getFirstElement(); return server; }/*from www . ja v a 2 s. co m*/ } return null; }
From source file:org.apache.directory.studio.ldapservers.views.ServersView.java
License:Apache License
/** * Enables or disables the actions according to the current selection * in the viewer.//from ww w.j a v a2 s .co m */ public void updateActionsStates() { // Getting the selection StructuredSelection selection = (StructuredSelection) tableViewer.getSelection(); if (!selection.isEmpty()) { LdapServer server = (LdapServer) selection.getFirstElement(); switch (server.getStatus()) { case STARTED: start.setEnabled(false); stop.setEnabled(true); break; case REPAIRING: case STARTING: start.setEnabled(false); stop.setEnabled(false); break; case STOPPED: start.setEnabled(true); stop.setEnabled(false); break; case STOPPING: start.setEnabled(false); stop.setEnabled(false); break; case UNKNOWN: start.setEnabled(false); stop.setEnabled(false); break; } openConfiguration.setEnabled(server.getLdapServerAdapterExtension().isOpenConfigurationActionEnabled()); delete.setEnabled(true); rename.setEnabled(true); properties.setEnabled(true); } else { openConfiguration.setEnabled(false); delete.setEnabled(false); rename.setEnabled(false); start.setEnabled(false); stop.setEnabled(false); properties.setEnabled(false); } }
From source file:org.apache.directory.studio.ldapservers.wizards.NewServerWizardSelectionPage.java
License:Apache License
/** * Adding listeners to UI elements./*from w w w. j ava 2 s. co m*/ */ private void addListeners() { // Filter Text filterText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { // Refreshing the LDAP Server Adapters Tree Viewer ldapServerAdaptersTreeViewer.refresh(); ldapServerAdaptersTreeViewer.expandAll(); } }); // LDAP Server Adapters Tree Viewer ldapServerAdaptersTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // Assigning an automatic name to the LDAP Server based on the selected LDAP Server Adapter Extension serverNameText .setText(getServerName((StructuredSelection) ldapServerAdaptersTreeViewer.getSelection())); // getContainer().updateButtons(); validate(); } /** * Get a name for the server based on the current selection. * * @param selection * the current selection * @return * a name for the server based on the current selection */ private String getServerName(StructuredSelection selection) { if (!selection.isEmpty()) { Object selectedObject = selection.getFirstElement(); if (selectedObject instanceof LdapServerAdapterExtension) { // Getting the name of the LDAP Server Adapter Extension String serverName = labelProvider.getText(selection.getFirstElement()); // Checking if the name if available if (ldapServersManager.isNameAvailable(serverName)) { return serverName; } else { // The name is not available, looking for another name String newServerName = serverName; for (int i = 2; !ldapServersManager.isNameAvailable(newServerName); i++) { newServerName = serverName + " (" + i + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } return newServerName; } } } // Returning an empty string if the selection is empty or if the current selection is a vendor return ""; //$NON-NLS-1$ } }); // Server Name Text serverNameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validate(); } }); }
From source file:org.apache.directory.studio.ldapservers.wizards.NewServerWizardSelectionPage.java
License:Apache License
/** * Validates the page./* w ww. j av a 2 s .com*/ */ private void validate() { displayErrorMessage(null); // LDAP Server Adapters Tree Viewer StructuredSelection selection = (StructuredSelection) ldapServerAdaptersTreeViewer.getSelection(); if (selection.isEmpty()) { displayErrorMessage(Messages.getString("NewServerWizardSelectionPage.ChooseTypeOfServerToCreate")); //$NON-NLS-1$ return; } else { Object selectedObject = selection.getFirstElement(); if (selectedObject instanceof String) { displayErrorMessage(Messages.getString("NewServerWizardSelectionPage.ChooseTypeOfServerToCreate")); //$NON-NLS-1$ return; } } // Server Name Text String name = serverNameText.getText(); if ((name != null)) { if ("".equals(name)) //$NON-NLS-1$ { displayErrorMessage(Messages.getString("NewServerWizardSelectionPage.EnterANameForLdapServer")); //$NON-NLS-1$ return; } if (!ldapServersManager.isNameAvailable(name)) { displayErrorMessage( Messages.getString("NewServerWizardSelectionPage.LdapServerWithSameNameAlreadyExists")); //$NON-NLS-1$ return; } } }
From source file:org.apache.directory.studio.ldapservers.wizards.NewServerWizardSelectionPage.java
License:Apache License
/** * Gets the Ldap Server Adapter Extension. * * @return/*from w ww .j a va2s .com*/ * the Ldap Server Adapter Extension */ public LdapServerAdapterExtension getLdapServerAdapterExtension() { StructuredSelection selection = (StructuredSelection) ldapServerAdaptersTreeViewer.getSelection(); if (!selection.isEmpty()) { Object selectedObject = selection.getFirstElement(); if (selectedObject instanceof LdapServerAdapterExtension) { return (LdapServerAdapterExtension) selectedObject; } } return null; }
From source file:org.apache.directory.studio.openldap.common.ui.dialogs.PasswordDialog.java
License:Apache License
/** * Gets the selected new password hash method. * * @return the selected new password hash method *///from w w w . ja v a 2 s. c om private LdapSecurityConstants getSelectedNewPasswordHashMethod() { StructuredSelection selection = (StructuredSelection) newPasswordHashMethodComboViewer.getSelection(); if (!selection.isEmpty()) { Object selectedObject = selection.getFirstElement(); if (selectedObject instanceof LdapSecurityConstants) { return (LdapSecurityConstants) selectedObject; } } return null; }