List of usage examples for org.eclipse.jface.viewers StructuredSelection size
@Override public int size()
From source file:org.apache.directory.studio.ldapservers.actions.StopAction.java
License:Apache License
/** * {@inheritDoc}/*from ww w .j av a 2 s . 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(); // 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}//from w ww . jav a 2 s .c o 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; }/* w ww. j a v a2s. co m*/ } return null; }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.CloseProjectAction.java
License:Apache License
/** * Enables or disables the Action./*from ww w. jav a2 s.c om*/ */ private void enableDisable() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { setEnabled(((ProjectWrapper) selection.getFirstElement()).getProject().getState() .equals(ProjectState.OPEN)); } else { setEnabled(false); } }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.CloseProjectAction.java
License:Apache License
/** * {@inheritDoc}//w w w . java2 s . com */ public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { projectsHandler.closeProject(((ProjectWrapper) selection.getFirstElement()).getProject()); } }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.DeleteProjectAction.java
License:Apache License
/** * Creates a new instance of DeleteProjectAction. * * @param view/*from w w w. j a va 2 s . c o m*/ * the associated view */ public DeleteProjectAction(TableViewer viewer) { super(Messages.getString("DeleteProjectAction.DeleteProjectAction")); //$NON-NLS-1$ setToolTipText(Messages.getString("DeleteProjectAction.DeleteProjectToolTip")); //$NON-NLS-1$ setId(PluginConstants.CMD_DELETE_PROJECT); setActionDefinitionId(PluginConstants.CMD_DELETE_PROJECT); setImageDescriptor(Activator.getDefault().getImageDescriptor(PluginConstants.IMG_DELETE)); setEnabled(false); this.viewer = viewer; this.viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection.size() == 1) { setText(Messages.getString("DeleteProjectAction.DeleteProjectAction")); //$NON-NLS-1$ setEnabled(true); } else if (selection.size() > 1) { setText(Messages.getString("DeleteProjectAction.DeleteProjectsAction")); //$NON-NLS-1$ setEnabled(true); } else { setText(Messages.getString("DeleteProjectAction.DeleteProjectAction")); //$NON-NLS-1$ setEnabled(false); } } }); }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.DeleteProjectAction.java
License:Apache License
/** * {@inheritDoc}// w ww. j a v a 2 s . co m */ public void run() { ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler(); StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { StringBuilder title = new StringBuilder(); StringBuilder message = new StringBuilder(); int count = selection.size(); if (count <= 5) { if (count == 1) { // Only 1 project to delete title.append(Messages.getString("DeleteProjectAction.DeleteProjectTitle")); //$NON-NLS-1$ message.append(Messages.getString("DeleteProjectAction.SureDeleteFollowingProject")); //$NON-NLS-1$ } else { // Between 2 to 5 projects to delete title.append(Messages.getString("DeleteProjectAction.DeleteProjectsTitle")); //$NON-NLS-1$ message.append(Messages.getString("DeleteProjectAction.SureDeleteFollowingProjects")); //$NON-NLS-1$ } // Appending the projects names for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { message.append(ConnectionCoreConstants.LINE_SEPARATOR); message.append(" - "); //$NON-NLS-1$ message.append(((ProjectWrapper) iterator.next()).getProject().getName()); } } else { // More than 5 projects to delete title.append(Messages.getString("DeleteProjectAction.DeleteProjectsTitle")); //$NON-NLS-1$ message.append(Messages.getString("DeleteProjectAction.SureDeleteSelectedProjects")); //$NON-NLS-1$ } // Showing the confirmation window if (MessageDialog.openConfirm(viewer.getControl().getShell(), title.toString(), message.toString())) { for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { ProjectWrapper wrapper = (ProjectWrapper) iterator.next(); Project project = wrapper.getProject(); if (project.getState() == ProjectState.OPEN) { // Closing the project before removing it. projectsHandler.closeProject(project); } projectsHandler.removeProject(project); } } } }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.DeleteSchemaElementAction.java
License:Apache License
/** * Creates a new instance of DeleteSchemaElementAction. *///from www . ja va 2 s . c o m public DeleteSchemaElementAction(TreeViewer viewer) { super(Messages.getString("DeleteSchemaElementAction.DeleteAction")); //$NON-NLS-1$ setToolTipText(Messages.getString("DeleteSchemaElementAction.DeleteToolTip")); //$NON-NLS-1$ setId(PluginConstants.CMD_DELETE_SCHEMA_ELEMENT); setActionDefinitionId(PluginConstants.CMD_DELETE_SCHEMA_ELEMENT); setImageDescriptor(Activator.getDefault().getImageDescriptor(PluginConstants.IMG_DELETE)); setEnabled(true); this.viewer = viewer; this.viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); if (selection.size() > 0) { boolean enabled = true; for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object selectedItem = iterator.next(); if (!(selectedItem instanceof SchemaWrapper) && !(selectedItem instanceof AttributeTypeWrapper) && !(selectedItem instanceof ObjectClassWrapper)) { enabled = false; break; } } setEnabled(enabled); } else { setEnabled(false); } } }); }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.DeleteSchemaElementAction.java
License:Apache License
/** * {@inheritDoc}// w w w . j ava2s . c o m */ public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { StringBuilder message = new StringBuilder(); int count = selection.size(); if (count == 1) { Object firstElement = selection.getFirstElement(); if (firstElement instanceof AttributeTypeWrapper) { message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteAttributeType")); //$NON-NLS-1$ } else if (firstElement instanceof ObjectClassWrapper) { message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteObjectClass")); //$NON-NLS-1$ } else if (firstElement instanceof SchemaWrapper) { message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteSchema")); //$NON-NLS-1$ } else { message.append(Messages.getString("DeleteSchemaElementAction.SureDeleteItem")); //$NON-NLS-1$ } } else { message.append(NLS.bind(Messages.getString("DeleteSchemaElementAction.SureDeleteItems"), //$NON-NLS-1$ new Object[] { count })); } // Showing the confirmation window if (MessageDialog.openConfirm(viewer.getControl().getShell(), Messages.getString("DeleteSchemaElementAction.DeleteTitle"), message.toString())) //$NON-NLS-1$ { Map<String, Schema> schemasMap = new HashMap<String, Schema>(); List<SchemaObject> schemaObjectsList = new ArrayList<SchemaObject>(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object selectedItem = iterator.next(); if (selectedItem instanceof SchemaWrapper) { Schema schema = ((SchemaWrapper) selectedItem).getSchema(); schemasMap.put(Strings.toLowerCase(schema.getSchemaName()), schema); } else if (selectedItem instanceof AttributeTypeWrapper) { AttributeType at = ((AttributeTypeWrapper) selectedItem).getAttributeType(); schemaObjectsList.add(at); } else if (selectedItem instanceof ObjectClassWrapper) { ObjectClass oc = ((ObjectClassWrapper) selectedItem).getObjectClass(); schemaObjectsList.add(oc); } } SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler(); // Removing schema objects for (SchemaObject schemaObject : schemaObjectsList) { if (!schemasMap.containsKey(Strings.toLowerCase(schemaObject.getSchemaName()))) { // If the schema object is not part of deleted schema, we need to delete it. // But, we don't delete schema objects that are part of a deleted schema, since // deleting the schema will also delete this schema object. if (schemaObject instanceof AttributeType) { schemaHandler.removeAttributeType((AttributeType) schemaObject); } else if (schemaObject instanceof ObjectClass) { schemaHandler.removeObjectClass((ObjectClass) schemaObject); } } } // Removing schemas for (Schema schema : schemasMap.values()) { schemaHandler.removeSchema(schema); } } } }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.ExportProjectsAction.java
License:Apache License
/** * {@inheritDoc}/*from w w w . ja v a 2s .c o m*/ */ public void run() { List<Project> selectedProjects = new ArrayList<Project>(); // Getting the selection StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() > 0)) { for (Iterator<?> i = selection.iterator(); i.hasNext();) { selectedProjects.add(((ProjectWrapper) i.next()).getProject()); } } // Instantiates and initializes the wizard ExportProjectsWizard wizard = new ExportProjectsWizard(); wizard.setSelectedProjects(selectedProjects.toArray(new Project[0])); wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY); // Instantiates the wizard container with the wizard and opens it WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard); dialog.create(); dialog.open(); }