List of usage examples for org.eclipse.jface.viewers StructuredSelection getFirstElement
@Override
public Object getFirstElement()
From source file:org.apache.directory.studio.schemaeditor.controller.actions.RenameSchemaElementAction.java
License:Apache License
/** * Creates a new instance of RenameProjectAction. * * @param viewer// w ww.j a va2 s . com * the associated viewer */ public RenameSchemaElementAction(TreeViewer viewer) { super(Messages.getString("RenameSchemaElementAction.RenameSchemaElementAction")); //$NON-NLS-1$ setToolTipText(getText()); setId(PluginConstants.CMD_RENAME_SCHEMA_ELEMENT); setActionDefinitionId(PluginConstants.CMD_RENAME_SCHEMA_ELEMENT); setImageDescriptor(Activator.getDefault().getImageDescriptor(PluginConstants.IMG_RENAME)); setEnabled(false); this.viewer = viewer; this.viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); setEnabled((selection.size() == 1) && ((selection.getFirstElement() instanceof SchemaWrapper) || (selection.getFirstElement() instanceof AttributeTypeWrapper) || (selection.getFirstElement() instanceof ObjectClassWrapper))); } }); }
From source file:org.apache.directory.studio.schemaeditor.controller.actions.RenameSchemaElementAction.java
License:Apache License
/** * {@inheritDoc}/*from w ww .j a v a 2 s . co m*/ */ public void run() { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { Object selectedElement = selection.getFirstElement(); // Saving all dirty editors before processing the renaming if (EditorsUtils.saveAllDirtyEditors()) { // SCHEMA if (selectedElement instanceof SchemaWrapper) { Schema schema = ((SchemaWrapper) selectedElement).getSchema(); RenameSchemaDialog dialog = new RenameSchemaDialog(schema.getSchemaName()); if (dialog.open() == RenameSchemaDialog.OK) { Activator.getDefault().getSchemaHandler().renameSchema(schema, dialog.getNewName()); } } // ATTRIBUTE TYPE else if (selectedElement instanceof AttributeTypeWrapper) { MutableAttributeType attributeType = (MutableAttributeType) ((AttributeTypeWrapper) selectedElement) .getAttributeType(); RenameAttributeTypeDialog dialog = new RenameAttributeTypeDialog(attributeType.getNames()); if (dialog.open() == RenameAttributeTypeDialog.OK) { MutableAttributeType modifiedAttributeType = PluginUtils.getClone(attributeType); modifiedAttributeType.setNames(dialog.getAliases()); Activator.getDefault().getSchemaHandler().modifyAttributeType(attributeType, modifiedAttributeType); } } // OBJECT CLASS else if (selectedElement instanceof ObjectClassWrapper) { MutableObjectClass objectClass = (MutableObjectClass) ((ObjectClassWrapper) selectedElement) .getObjectClass(); RenameObjectClassDialog dialog = new RenameObjectClassDialog(objectClass.getNames()); if (dialog.open() == RenameObjectClassDialog.OK) { ObjectClass modifiedObjectClass = PluginUtils.getClone(objectClass); modifiedObjectClass.setNames(dialog.getAliases()); Activator.getDefault().getSchemaHandler().modifyObjectClass(objectClass, modifiedObjectClass); } } } } }
From source file:org.apache.directory.studio.schemaeditor.controller.ProblemsViewController.java
License:Apache License
/** * Initializes the DoubleClickListener.//from w w w .j a v a2 s . c o m */ private void initDoubleClickListener() { view.getViewer().addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); TreeViewer viewer = view.getViewer(); // What we get from the treeViewer is a StructuredSelection StructuredSelection selection = (StructuredSelection) event.getSelection(); // Here's the real object (an AttributeTypeWrapper, ObjectClassWrapper or IntermediateNode) Object objectSelection = selection.getFirstElement(); IEditorInput input = null; String editorId = null; // Selecting the right editor and input if (objectSelection instanceof SchemaErrorWrapper) { SchemaObject object = ((SchemaErrorWrapper) objectSelection).getLdapSchemaException() .getSourceObject(); if (object instanceof AttributeType) { input = new AttributeTypeEditorInput( Activator.getDefault().getSchemaHandler().getAttributeType(object.getOid())); editorId = AttributeTypeEditor.ID; } else if (object instanceof ObjectClass) { input = new ObjectClassEditorInput( Activator.getDefault().getSchemaHandler().getObjectClass(object.getOid())); editorId = ObjectClassEditor.ID; } } else if (objectSelection instanceof SchemaWarningWrapper) { SchemaObject object = ((SchemaWarningWrapper) objectSelection).getSchemaWarning().getSource(); if (object instanceof AttributeType) { input = new AttributeTypeEditorInput((AttributeType) object); editorId = AttributeTypeEditor.ID; } else if (object instanceof ObjectClass) { input = new ObjectClassEditorInput((MutableObjectClass) object); editorId = ObjectClassEditor.ID; } } else if ((objectSelection instanceof Folder)) { // Here we don't open an editor, we just expand the node. viewer.setExpandedState(objectSelection, !viewer.getExpandedState(objectSelection)); } // Let's open the editor if (input != null) { try { page.openEditor(input, editorId); } catch (PartInitException e) { PluginUtils.logError(Messages.getString("ProblemsViewController.ErrorOpeningEditor"), e); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog(Messages.getString("ProblemsViewController.Error"), //$NON-NLS-1$ Messages.getString("ProblemsViewController.ErrorOpeningEditor")); //$NON-NLS-1$ } } } }); }
From source file:org.apache.directory.studio.schemaeditor.controller.ProjectsViewController.java
License:Apache License
/** * Initializes the DoubleClickListener.// w w w . jav a 2s . c o m */ private void initDoubleClickListener() { viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { Project project = ((ProjectWrapper) selection.getFirstElement()).getProject(); if (project.getState().equals(ProjectState.CLOSED)) { projectsHandler.openProject(project); } } } }); }
From source file:org.apache.directory.studio.schemaeditor.controller.SchemaViewController.java
License:Apache License
/** * Initializes the DoubleClickListener.//from www . j a v a 2 s . c o m */ private void initDoubleClickListener() { viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); TreeViewer viewer = view.getViewer(); // What we get from the viewer is a StructuredSelection StructuredSelection selection = (StructuredSelection) event.getSelection(); // Here's the real object (an AttributeTypeWrapper, ObjectClassWrapper or IntermediateNode) Object objectSelection = selection.getFirstElement(); IEditorInput input = null; String editorId = null; // Selecting the right editor and input if (objectSelection instanceof AttributeTypeWrapper) { input = new AttributeTypeEditorInput( ((AttributeTypeWrapper) objectSelection).getAttributeType()); editorId = AttributeTypeEditor.ID; } else if (objectSelection instanceof ObjectClassWrapper) { input = new ObjectClassEditorInput(((ObjectClassWrapper) objectSelection).getObjectClass()); editorId = ObjectClassEditor.ID; } else if ((objectSelection instanceof Folder) || (objectSelection instanceof SchemaWrapper)) { // Here we don't open an editor, we just expand the node. viewer.setExpandedState(objectSelection, !viewer.getExpandedState(objectSelection)); } // Let's open the editor if (input != null) { try { page.openEditor(input, editorId); } catch (PartInitException e) { PluginUtils.logError(Messages.getString("SchemaViewController.ErrorOpeningEditor"), e); //$NON-NLS-1$ ViewUtils.displayErrorMessageDialog(Messages.getString("SchemaViewController.error"), //$NON-NLS-1$ Messages.getString("SchemaViewController.ErrorOpeningEditor")); //$NON-NLS-1$ } } } }); }
From source file:org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog.java
License:Apache License
/** * {@inheritDoc}//from ww w . j av a 2 s. c o m */ protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); composite.setLayout(layout); Label chooseLabel = new Label(composite, SWT.NONE); chooseLabel.setText(Messages.getString("AttributeTypeSelectionDialog.ChooseAType")); //$NON-NLS-1$ chooseLabel.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); searchText = new Text(composite, SWT.BORDER | SWT.SEARCH); searchText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); searchText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { setSearchInput(searchText.getText()); } }); searchText.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN) { attributeTypesTable.setFocus(); } } }); Label matchingLabel = new Label(composite, SWT.NONE); matchingLabel.setText(Messages.getString("AttributeTypeSelectionDialog.MatchingTypes")); //$NON-NLS-1$ matchingLabel.setLayoutData(new GridData(SWT.FILL, SWT.None, true, false)); attributeTypesTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); gridData.heightHint = 148; gridData.minimumHeight = 148; gridData.widthHint = 350; gridData.minimumWidth = 350; attributeTypesTable.setLayoutData(gridData); attributeTypesTable.addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { if (attributeTypesTable.getSelectionIndex() != -1) { okPressed(); } } }); attributeTypesTableViewer = new TableViewer(attributeTypesTable); attributeTypesTableViewer .setContentProvider(new AttributeTypeSelectionDialogContentProvider(hiddenAttributeTypes)); attributeTypesTableViewer .setLabelProvider(new DecoratingLabelProvider(new AttributeTypeSelectionDialogLabelProvider(), Activator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator())); attributeTypesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) attributeTypesTableViewer.getSelection(); if (selection.isEmpty()) { if ((chooseButton != null) && (!chooseButton.isDisposed())) { chooseButton.setEnabled(false); } schemaIconLabel .setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16)); schemaNameLabel.setText(""); //$NON-NLS-1$ } else { if ((chooseButton != null) && (!chooseButton.isDisposed())) { chooseButton.setEnabled(true); } schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_SCHEMA)); schemaNameLabel.setText(((AttributeType) selection.getFirstElement()).getSchemaName()); } } }); // Schema Composite Composite schemaComposite = new Composite(composite, SWT.BORDER); schemaComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); GridLayout schemaCompositeGridLayout = new GridLayout(2, false); schemaCompositeGridLayout.horizontalSpacing = 0; schemaCompositeGridLayout.verticalSpacing = 0; schemaCompositeGridLayout.marginWidth = 2; schemaCompositeGridLayout.marginHeight = 2; schemaComposite.setLayout(schemaCompositeGridLayout); // Schema Icon Label schemaIconLabel = new Label(schemaComposite, SWT.NONE); GridData schemaIconLabelGridData = new GridData(SWT.NONE, SWT.BOTTOM, false, false); schemaIconLabelGridData.widthHint = 18; schemaIconLabelGridData.heightHint = 16; schemaIconLabel.setLayoutData(schemaIconLabelGridData); schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16)); // Schema Name Label schemaNameLabel = new Label(schemaComposite, SWT.NONE); schemaNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false)); schemaNameLabel.setText(""); //$NON-NLS-1$ // We need to force the input to load the complete list of attribute types setSearchInput(""); //$NON-NLS-1$ return composite; }
From source file:org.apache.directory.studio.schemaeditor.view.dialogs.AttributeTypeSelectionDialog.java
License:Apache License
/** * {@inheritDoc}/*w w w . j ava2 s. c o m*/ */ protected void okPressed() { StructuredSelection selection = (StructuredSelection) attributeTypesTableViewer.getSelection(); if (selection.isEmpty()) { MessageDialog.openError(getShell(), Messages.getString("AttributeTypeSelectionDialog.InvalidSelection"), //$NON-NLS-1$ Messages.getString("AttributeTypeSelectionDialog.MustChooseType")); //$NON-NLS-1$ return; } else { selectedAttributeType = (AttributeType) selection.getFirstElement(); } super.okPressed(); }
From source file:org.apache.directory.studio.schemaeditor.view.dialogs.ObjectClassSelectionDialog.java
License:Apache License
/** * {@inheritDoc}//from w ww . j a v a 2s .co m */ protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); composite.setLayout(layout); Label chooseLabel = new Label(composite, SWT.NONE); chooseLabel.setText(Messages.getString("ObjectClassSelectionDialog.ChooseClass")); //$NON-NLS-1$ chooseLabel.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); searchText = new Text(composite, SWT.BORDER | SWT.SEARCH); searchText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); searchText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { setSearchInput(searchText.getText()); } }); searchText.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_DOWN) { objectClassesTable.setFocus(); } } }); Label matchingLabel = new Label(composite, SWT.NONE); matchingLabel.setText(Messages.getString("ObjectClassSelectionDialog.MatchingClasses")); //$NON-NLS-1$ matchingLabel.setLayoutData(new GridData(SWT.FILL, SWT.None, true, false)); objectClassesTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); gridData.heightHint = 148; gridData.minimumHeight = 148; gridData.widthHint = 350; gridData.minimumWidth = 350; objectClassesTable.setLayoutData(gridData); objectClassesTable.addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { if (objectClassesTable.getSelectionIndex() != -1) { okPressed(); } } }); objectClassesTableViewer = new TableViewer(objectClassesTable); objectClassesTableViewer .setContentProvider(new ObjectClassSelectionDialogContentProvider(hiddenObjectClasses)); objectClassesTableViewer .setLabelProvider(new DecoratingLabelProvider(new ObjectClassSelectionDialogLabelProvider(), Activator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator())); objectClassesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) objectClassesTableViewer.getSelection(); if (selection.isEmpty()) { if ((chooseButton != null) && (!chooseButton.isDisposed())) { chooseButton.setEnabled(false); } schemaIconLabel .setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16)); schemaNameLabel.setText(""); //$NON-NLS-1$ } else { if ((chooseButton != null) && (!chooseButton.isDisposed())) { chooseButton.setEnabled(true); } schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_SCHEMA)); schemaNameLabel.setText(((ObjectClass) selection.getFirstElement()).getSchemaName()); } } }); // Schema Composite Composite schemaComposite = new Composite(composite, SWT.BORDER); schemaComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); GridLayout schemaCompositeGridLayout = new GridLayout(2, false); schemaCompositeGridLayout.horizontalSpacing = 0; schemaCompositeGridLayout.verticalSpacing = 0; schemaCompositeGridLayout.marginWidth = 2; schemaCompositeGridLayout.marginHeight = 2; schemaComposite.setLayout(schemaCompositeGridLayout); // Schema Icon Label schemaIconLabel = new Label(schemaComposite, SWT.NONE); GridData schemaIconLabelGridData = new GridData(SWT.NONE, SWT.BOTTOM, false, false); schemaIconLabelGridData.widthHint = 18; schemaIconLabelGridData.heightHint = 16; schemaIconLabel.setLayoutData(schemaIconLabelGridData); schemaIconLabel.setImage(Activator.getDefault().getImage(PluginConstants.IMG_TRANSPARENT_16X16)); // Schema Name Label schemaNameLabel = new Label(schemaComposite, SWT.NONE); schemaNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false)); schemaNameLabel.setText(""); //$NON-NLS-1$ // We need to force the input to load the complete list of attribute types setSearchInput(""); //$NON-NLS-1$ return composite; }
From source file:org.apache.directory.studio.schemaeditor.view.dialogs.ObjectClassSelectionDialog.java
License:Apache License
/** * {@inheritDoc}/* w w w .j ava 2 s. c om*/ */ protected void okPressed() { StructuredSelection selection = (StructuredSelection) objectClassesTableViewer.getSelection(); if (selection.isEmpty()) { MessageDialog.openError(getShell(), Messages.getString("ObjectClassSelectionDialog.InvalidSelection"), //$NON-NLS-1$ Messages.getString("ObjectClassSelectionDialog.MustChooseClass")); //$NON-NLS-1$ return; } else { selectedObjectClass = (ObjectClass) selection.getFirstElement(); } super.okPressed(); }