List of usage examples for org.eclipse.jface.viewers StructuredSelection iterator
@Override
public Iterator iterator()
From source file:org.eclipse.ui.ide.markers.compatibility.internal.ExtendedMarkersView.java
License:Open Source License
/** * Set the selection of the receiver. reveal the item if reveal is true. * /*from www.j a v a 2 s . c o m*/ * @param structuredSelection * @param reveal */ void setSelection(StructuredSelection structuredSelection, boolean reveal) { List newSelection = new ArrayList(structuredSelection.size()); for (Iterator i = structuredSelection.iterator(); i.hasNext();) { Object next = i.next(); if (next instanceof IMarker) { MarkerItem marker = builder.getMarkerItem((IMarker) next); if (marker != null) { newSelection.add(marker); } } } viewer.setSelection(new StructuredSelection(newSelection), reveal); }
From source file:org.eclipse.ui.internal.intro.universal.CustomizationContentsArea.java
License:Open Source License
private void fillPopupMenu(IMenuManager manager, final TableViewer viewer) { StructuredSelection ssel = (StructuredSelection) viewer.getSelection(); manager.add(new Separator()); Action addSeparator = new Action(Messages.WelcomeCustomizationPreferencePage_addSeparator) { public void run() { doAddSeparator(viewer);//from ww w . j av a2 s .com } }; manager.add(addSeparator); manager.add(new Separator()); if (ssel.size() == 1 && viewer != available) { Action upAction = new Action(Messages.WelcomeCustomizationPreferencePage_up) { public void run() { doMove(viewer, true); } }; Action downAction = new Action(Messages.WelcomeCustomizationPreferencePage_down) { public void run() { doMove(viewer, false); } }; BaseData ed = (BaseData) ssel.getFirstElement(); GroupData gd = (GroupData) viewer.getInput(); upAction.setEnabled(gd.canMoveUp(ed)); downAction.setEnabled(gd.canMoveDown(ed)); manager.add(upAction); manager.add(downAction); } if (ssel.size() > 0) { manager.add(new Separator()); MenuManager menu = new MenuManager(Messages.WelcomeCustomizationPreferencePage_moveTo); addMoveToAction(menu, available, viewer, Messages.WelcomeCustomizationPreferencePage_menu_available); addMoveToAction(menu, topLeft, viewer, Messages.WelcomeCustomizationPreferencePage_menu_top_left); addMoveToAction(menu, topRight, viewer, Messages.WelcomeCustomizationPreferencePage_menu_top_right); addMoveToAction(menu, bottomLeft, viewer, Messages.WelcomeCustomizationPreferencePage_menu_bottom_left); addMoveToAction(menu, bottomRight, viewer, Messages.WelcomeCustomizationPreferencePage_menu_bottom_right); manager.add(menu); boolean addDeleteSeparator = false; for (Iterator iter = ssel.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj instanceof SeparatorData) addDeleteSeparator = true; else { addDeleteSeparator = false; break; } } if (addDeleteSeparator) { Action deleteSeparator = new Action(Messages.WelcomeCustomizationPreferencePage_removeSeparator) { public void run() { doRemoveSeparators(viewer); } }; manager.add(deleteSeparator); } } }
From source file:org.eclipse.ui.internal.intro.universal.CustomizationContentsArea.java
License:Open Source License
private void doRemoveSeparators(Viewer viewer) { StructuredSelection ssel = ((StructuredSelection) viewer.getSelection()); GroupData gd = (GroupData) viewer.getInput(); for (Iterator iter = ssel.iterator(); iter.hasNext();) { SeparatorData sdata = (SeparatorData) iter.next(); gd.remove(sdata);// w ww .j a v a 2 s.c om } viewer.refresh(); }
From source file:org.eclipse.ui.internal.views.markers.ExtendedMarkersView.java
License:Open Source License
/** * Set the selection of the receiver. reveal the item if reveal is true. * // w w w. j av a2 s . com * @param structuredSelection * @param reveal */ void setSelection(StructuredSelection structuredSelection, boolean reveal) { List newSelection = new ArrayList(structuredSelection.size()); for (Iterator i = structuredSelection.iterator(); i.hasNext();) { Object next = i.next(); if (next instanceof IMarker) { MarkerItem marker = builder.getMarkers().getMarkerItem((IMarker) next); if (marker != null) { newSelection.add(marker); } } } IStructuredSelection structured = new StructuredSelection(newSelection); viewer.setSelection(structured, reveal); updateStatusLine(structured); }
From source file:org.eclipse.wst.ide.remote.ui.internal.view.MonitorView.java
License:Open Source License
/** * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) *///from www .ja v a 2 s . c o m public void createPartControl(Composite parent) { SashForm sashFparent = new SashForm(parent, SWT.VERTICAL); sashFparent.setBackground(sashFparent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.horizontalSpacing = 4; layout.verticalSpacing = 4; sashFparent.setLayout(layout); sashFparent.setLayoutData(new GridData(GridData.FILL_BOTH)); PlatformUI.getWorkbench().getHelpSystem().setHelp(sashFparent, ContextIds.VIEW); // create tree panel Composite treePanel = new Composite(sashFparent, SWT.NONE); layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; treePanel.setLayout(layout); GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); data.heightHint = 110; data.horizontalSpan = 2; treePanel.setLayoutData(data); tree = new Tree(treePanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); data = new GridData(GridData.FILL_BOTH); //data.widthHint = 120; tree.setLayoutData(data); treeViewer = new TreeViewer(tree); contentProvider = new MonitorTreeContentProvider(); treeViewer.setContentProvider(contentProvider); treeViewer.setInput(MonitorTreeContentProvider.ROOT); treeViewer.setLabelProvider(new TreeLabelProvider()); PlatformUI.getWorkbench().getHelpSystem().setHelp(tree, ContextIds.VIEW_TREE); Composite buttonsPanel = new Composite(treePanel, SWT.NONE); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 0; buttonsPanel.setLayout(layout); data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); data.widthHint = 350; buttonsPanel.setLayoutData(data); start = SWTUtil.createButton(buttonsPanel, Messages.start); stop = SWTUtil.createButton(buttonsPanel, Messages.stop); stop.setEnabled(false); data = (GridData) start.getLayoutData(); data.verticalIndent = 9; start.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IMonitor[] monitors = MonitorCore.getMonitors(); try { monitors[0].start(); } catch (CoreException ce) { } catch (Exception ce) { } if (monitors[0].isRunning()) { start.setEnabled(false); stop.setEnabled(true); } tableViewer.setSelection(tableViewer.getSelection()); } }); stop.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IMonitor[] monitors = MonitorCore.getMonitors(); try { monitors[0].stop(); } catch (Exception ex) { // ignore } if (!monitors[0].isRunning()) { start.setEnabled(true); stop.setEnabled(false); } tableViewer.setSelection(tableViewer.getSelection()); } }); final Button properties = SWTUtil.createButton(buttonsPanel, Messages.actionProperties); properties.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { showPreferencePage(); } }); // create center and right panels SashForm sashFchild = new SashForm(sashFparent, SWT.HORIZONTAL); layout = new GridLayout(); layout.numColumns = 2; layout.horizontalSpacing = 2; layout.verticalSpacing = 4; sashFchild.setLayout(layout); sashFparent.setWeights(new int[] { 30, 70 }); // request panel Composite request = new Composite(sashFchild, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; request.setLayout(layout); request.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite requestHeader = new Composite(request, SWT.NONE); layout = new GridLayout(); layout.verticalSpacing = 1; layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); requestHeader.setLayout(layout); requestHeader.setLayoutData(data); // response panel Composite response = new Composite(sashFchild, SWT.NONE); layout = new GridLayout(); layout.verticalSpacing = 3; layout.marginHeight = 0; layout.marginWidth = 0; response.setLayout(layout); response.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite responseHeader = new Composite(response, SWT.NONE); layout = new GridLayout(); layout.verticalSpacing = 1; layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); responseHeader.setLayout(layout); responseHeader.setLayoutData(data); // viewer manager vm = new ViewerManager(request, response); requestViewers = vm.getRequestViewers(); responseViewers = vm.getResponseViewers(); // selection listener treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); currentRequest = null; if (selection != null && !selection.isEmpty()) { StructuredSelection sel = (StructuredSelection) selection; currentSelection = sel; Object obj = sel.iterator().next(); if (obj instanceof Request) currentRequest = (Request) obj; } if (currentRequest != null) { vm.setRequest(currentRequest); Viewer viewer = vm.findViewer((String) currentRequest.getProperty("request-viewer")); if (viewer == null) viewer = vm.findViewer(DEFAULT_VIEWER); if (viewer != null) { } viewer = vm.findViewer((String) currentRequest.getProperty("response-viewer")); if (viewer == null && currentRequest.getName() != null) viewer = vm.getDefaultViewer(currentRequest.getName()); if (viewer != null) { vm.setResponseViewer(viewer); } } else { vm.setRequest(currentRequest); } } }); treeViewer.expandToLevel(2); // create a menu manager for a context menu MenuManager menuManager = new MenuManager(); menuManager.setRemoveAllWhenShown(true); menuManager.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager menu) { menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(preferenceAction); } }); // create the menu Menu menu = menuManager.createContextMenu(treeViewer.getControl()); treeViewer.getControl().setMenu(menu); // register the menu with the platform getSite().registerContextMenu(menuManager, treeViewer); initializeActions(); }
From source file:org.eclipse.wst.internet.monitor.ui.internal.view.MonitorView.java
License:Open Source License
/** * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) *//*from w w w. java2 s. c o m*/ public void createPartControl(Composite parent) { SashForm sashFparent = new SashForm(parent, SWT.VERTICAL); sashFparent.setBackground(sashFparent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.horizontalSpacing = 4; layout.verticalSpacing = 4; sashFparent.setLayout(layout); sashFparent.setLayoutData(new GridData(GridData.FILL_BOTH)); PlatformUI.getWorkbench().getHelpSystem().setHelp(sashFparent, ContextIds.VIEW); // create tree panel Composite treePanel = new Composite(sashFparent, SWT.NONE); layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; treePanel.setLayout(layout); GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); data.heightHint = 110; data.horizontalSpan = 2; treePanel.setLayoutData(data); tree = new Tree(treePanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); data = new GridData(GridData.FILL_BOTH); //data.widthHint = 120; tree.setLayoutData(data); treeViewer = new TreeViewer(tree); contentProvider = new MonitorTreeContentProvider(); treeViewer.setContentProvider(contentProvider); treeViewer.setInput(MonitorTreeContentProvider.ROOT); treeViewer.setLabelProvider(new TreeLabelProvider()); PlatformUI.getWorkbench().getHelpSystem().setHelp(tree, ContextIds.VIEW_TREE); Composite detailsPanel = new Composite(treePanel, SWT.NONE); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 2; layout.marginWidth = 0; detailsPanel.setLayout(layout); data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); data.widthHint = 350; detailsPanel.setLayoutData(data); final Text detailsTimeText = new Text(detailsPanel, SWT.READ_ONLY); detailsTimeText.setText(NLS.bind(Messages.viewTime, "")); detailsTimeText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); final Text detailsResponseTimeText = new Text(detailsPanel, SWT.READ_ONLY); detailsResponseTimeText.setText(NLS.bind(Messages.viewResponseTime, "")); detailsResponseTimeText .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); final Text detailsViewTimeText = new Text(detailsPanel, SWT.READ_ONLY); detailsViewTimeText.setText(NLS.bind(Messages.viewType, "")); detailsViewTimeText .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); // create center and right panels SashForm sashFchild = new SashForm(sashFparent, SWT.HORIZONTAL); layout = new GridLayout(); layout.numColumns = 2; layout.horizontalSpacing = 2; layout.verticalSpacing = 4; sashFchild.setLayout(layout); sashFparent.setWeights(new int[] { 30, 70 }); // request panel Composite request = new Composite(sashFchild, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; request.setLayout(layout); request.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite requestHeader = new Composite(request, SWT.NONE); layout = new GridLayout(); layout.verticalSpacing = 1; layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); requestHeader.setLayout(layout); requestHeader.setLayoutData(data); final Label requestViewerComboLabel = new Label(requestHeader, SWT.NONE); requestViewerComboLabel.setText(NLS.bind(Messages.viewRequestType, "")); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.verticalSpan = 1; data.horizontalIndent = 3; requestViewerComboLabel.setLayoutData(data); final Combo requestViewerCombo = new Combo(requestHeader, SWT.DROP_DOWN | SWT.READ_ONLY); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.verticalSpan = 1; requestViewerCombo.setLayoutData(data); final Text requestLabel = new Text(requestHeader, SWT.READ_ONLY); requestLabel.setText(NLS.bind(Messages.viewRequest, "")); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.verticalSpan = 1; data.horizontalSpan = 2; requestLabel.setLayoutData(data); final Text requestSizeLabel = new Text(requestHeader, SWT.READ_ONLY); requestSizeLabel.setText(NLS.bind(Messages.viewSize, "")); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.verticalSpan = 1; data.horizontalSpan = 2; requestSizeLabel.setLayoutData(data); // response panel Composite response = new Composite(sashFchild, SWT.NONE); layout = new GridLayout(); layout.verticalSpacing = 3; layout.marginHeight = 0; layout.marginWidth = 0; response.setLayout(layout); response.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite responseHeader = new Composite(response, SWT.NONE); layout = new GridLayout(); layout.verticalSpacing = 1; layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; layout.marginLeft = 0; data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); responseHeader.setLayout(layout); responseHeader.setLayoutData(data); final Label responseViewerComboLabel = new Label(responseHeader, SWT.NONE); responseViewerComboLabel.setText(NLS.bind(Messages.viewResponseType, "")); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.verticalSpan = 1; data.horizontalIndent = 3; responseViewerComboLabel.setLayoutData(data); final Combo responseViewerCombo = new Combo(responseHeader, SWT.DROP_DOWN | SWT.READ_ONLY); data = new GridData(GridData.HORIZONTAL_ALIGN_END); data.verticalSpan = 1; responseViewerCombo.setLayoutData(data); final Text responseLabel = new Text(responseHeader, SWT.READ_ONLY); responseLabel.setText(NLS.bind(Messages.viewResponse, "")); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.verticalSpan = 1; data.horizontalSpan = 2; requestLabel.setLayoutData(data); final Text responseSizeLabel = new Text(responseHeader, SWT.READ_ONLY); responseSizeLabel.setText(NLS.bind(Messages.viewSize, "")); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.verticalSpan = 1; data.horizontalSpan = 2; responseSizeLabel.setLayoutData(data); // viewer manager vm = new ViewerManager(request, response); requestViewers = vm.getRequestViewers(); responseViewers = vm.getResponseViewers(); // set up the viewer combo boxes Iterator iterator = requestViewers.iterator(); int ctr = 0; while (iterator.hasNext()) { Viewer viewer = (Viewer) iterator.next(); requestViewerCombo.add(viewer.getLabel(), ctr); if (viewer.getId().equals(DEFAULT_VIEWER)) { requestViewerCombo.select(ctr); vm.setRequestViewer(viewer); } ctr++; } requestViewerCombo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Viewer viewer = (Viewer) requestViewers.get(requestViewerCombo.getSelectionIndex()); if (currentRequest != null && viewer != null) currentRequest.setProperty("request-viewer", viewer.getId()); vm.setRequestViewer(viewer); } public void widgetDefaultSelected(SelectionEvent e) { // ignore } }); requestHeader.layout(true); iterator = responseViewers.iterator(); ctr = 0; while (iterator.hasNext()) { Viewer viewer = (Viewer) iterator.next(); responseViewerCombo.add(viewer.getLabel(), ctr); if (viewer.getId().equals(DEFAULT_VIEWER)) { responseViewerCombo.select(ctr); vm.setResponseViewer(viewer); } ctr++; } responseViewerCombo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Viewer viewer = (Viewer) responseViewers.get(responseViewerCombo.getSelectionIndex()); if (currentRequest != null && viewer != null) currentRequest.setProperty("response-viewer", viewer.getId()); vm.setResponseViewer(viewer); } public void widgetDefaultSelected(SelectionEvent e) { // ignore } }); responseHeader.layout(true); // selection listener treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); currentRequest = null; if (selection != null && !selection.isEmpty()) { StructuredSelection sel = (StructuredSelection) selection; currentSelection = sel; Object obj = sel.iterator().next(); if (obj instanceof Request) currentRequest = (Request) obj; } if (currentRequest != null) { detailsTimeText.setText(NLS.bind(Messages.viewTime, format.format(currentRequest.getDate()))); if (currentRequest.getResponseTime() == -1) detailsResponseTimeText.setText(NLS.bind(Messages.viewResponseTime, "")); else { String time = NLS.bind(Messages.viewResponseTimeFormat, currentRequest.getResponseTime() + ""); detailsResponseTimeText.setText(NLS.bind(Messages.viewResponseTime, time)); } detailsViewTimeText.setText(NLS.bind(Messages.viewType, currentRequest.getProtocol())); // request information requestLabel .setText(NLS.bind(Messages.viewRequest, "localhost:" + currentRequest.getLocalPort())); requestSizeLabel.setText(getSizeString(currentRequest.getRequest(Request.CONTENT), currentRequest.getRequest(Request.ALL))); // response information responseLabel.setText(NLS.bind(Messages.viewResponse, currentRequest.getRemoteHost() + ":" + currentRequest.getRemotePort())); responseSizeLabel.setText(getSizeString(currentRequest.getResponse(Request.CONTENT), currentRequest.getResponse(Request.ALL))); vm.setRequest(currentRequest); Viewer viewer = vm.findViewer((String) currentRequest.getProperty("request-viewer")); if (viewer == null) viewer = vm.findViewer(DEFAULT_VIEWER); if (viewer != null) { vm.setRequestViewer(viewer); requestViewerCombo.select(requestViewers.indexOf(viewer)); } viewer = vm.findViewer((String) currentRequest.getProperty("response-viewer")); if (viewer == null && currentRequest.getName() != null) viewer = vm.getDefaultViewer(currentRequest.getName()); if (viewer != null) { vm.setResponseViewer(viewer); responseViewerCombo.select(responseViewers.indexOf(viewer)); } } else { detailsTimeText.setText(NLS.bind(Messages.viewTime, "")); detailsResponseTimeText.setText(NLS.bind(Messages.viewResponseTime, "")); requestLabel.setText(NLS.bind(Messages.viewRequest, "")); requestSizeLabel.setText(NLS.bind(Messages.viewSize, "")); responseLabel.setText(NLS.bind(Messages.viewResponse, "")); responseSizeLabel.setText(NLS.bind(Messages.viewSize, "")); vm.setRequest(currentRequest); } } }); treeViewer.expandToLevel(2); // create a menu manager for a context menu MenuManager menuManager = new MenuManager(); menuManager.setRemoveAllWhenShown(true); menuManager.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager menu) { menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(preferenceAction); } }); // create the menu Menu menu = menuManager.createContextMenu(treeViewer.getControl()); treeViewer.getControl().setMenu(menu); // register the menu with the platform getSite().registerContextMenu(menuManager, treeViewer); initializeActions(); }
From source file:org.eclipse.wst.wsdl.ui.internal.WSDLSelectionMapper.java
License:Open Source License
public ISelection mapSelection(ISelection selection) { List list = new ArrayList(); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; for (Iterator i = structuredSelection.iterator(); i.hasNext();) { Object o = i.next();/*from w w w .j av a2 s . co m*/ if (o instanceof Adapter) { list.add(((Adapter) o).getTarget()); } else { list.add(o); } } } return new StructuredSelection(list); }
From source file:org.eclipse.wst.xsd.ui.internal.common.properties.sections.EnumerationsSection.java
License:Open Source License
public void widgetSelected(SelectionEvent e) { XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) input; if (e.widget == addButton) { List enumList = st.getEnumerationFacets(); String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList); //$NON-NLS-1$ AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, (XSDSimpleTypeDefinition) input); command.setValue(newName);/* ww w. j av a2 s . co m*/ getCommandStack().execute(command); enumerationsTable.refresh(); int newItemIndex = enumerationsTable.getTable().getItemCount() - 1; enumerationsTable.editElement(enumerationsTable.getElementAt(newItemIndex), 0); } else if (e.widget == addManyButton) { Display display = Display.getCurrent(); // if it is null, get the default one display = display == null ? Display.getDefault() : display; Shell parentShell = display.getActiveShell(); EnumerationsDialog dialog = new EnumerationsDialog(parentShell); dialog.setBlockOnOpen(true); int result = dialog.open(); if (result == Window.OK) { String text = dialog.getText(); String delimiter = dialog.getDelimiter(); StringTokenizer tokenizer = new StringTokenizer(text, delimiter); CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_ADD_ENUMERATIONS); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (dialog.isPreserveWhitespace() == false) { token = token.trim(); } AddEnumerationsCommand command = new AddEnumerationsCommand( Messages._UI_ACTION_ADD_ENUMERATIONS, (XSDSimpleTypeDefinition) input); command.setValue(token); compoundCommand.add(command); } getCommandStack().execute(compoundCommand); } enumerationsTable.refresh(); } else if (e.widget == deleteButton) { StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection(); if (selection != null) { Iterator i = selection.iterator(); CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_DELETE_ENUMERATION); while (i.hasNext()) { Object obj = i.next(); if (obj != null) { if (obj instanceof XSDEnumerationFacet) { XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) obj; DeleteCommand deleteCommand = new DeleteCommand(Messages._UI_ACTION_DELETE_ENUMERATION, enumFacet); compoundCommand.add(deleteCommand); } } } getCommandStack().execute(compoundCommand); enumerationsTable.refresh(); } } else if (e.widget == enumerationsTable.getTable()) { StructuredSelection selection = (StructuredSelection) enumerationsTable.getSelection(); if (selection.getFirstElement() != null) { deleteButton.setEnabled(true); } else { deleteButton.setEnabled(false); } } }
From source file:org.eclipse.wst.xsd.ui.internal.common.properties.sections.SpecificConstraintsWidget.java
License:Open Source License
public void widgetSelected(SelectionEvent e) { XSDSimpleTypeDefinition st = input;// ww w .jav a 2 s . c o m if (e.widget == addButton) { List enumList = st.getEnumerationFacets(); String newName = XSDCommonUIUtils.createUniqueEnumerationValue("value", enumList); //$NON-NLS-1$ if (kind == ENUMERATION) { CompoundCommand compoundCommand = new CompoundCommand(); XSDSimpleTypeDefinition targetSimpleType = null; if (feature != null) { XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils.getAnonymousSimpleType(feature, input); if (anonymousSimpleType == null) { anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); anonymousSimpleType.setBaseTypeDefinition(input); ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand( Messages._UI_ACTION_CHANGE_PATTERN, feature); changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); compoundCommand.add(changeToAnonymousCommand); input = anonymousSimpleType; } targetSimpleType = anonymousSimpleType; } else { targetSimpleType = input; } AddEnumerationsCommand command = new AddEnumerationsCommand(Messages._UI_ACTION_ADD_ENUMERATION, targetSimpleType); command.setValue(newName); compoundCommand.add(command); commandStack.execute(compoundCommand); setInput(input); constraintsTableViewer.refresh(); int newItemIndex = constraintsTableViewer.getTable().getItemCount() - 1; constraintsTableViewer.editElement(constraintsTableViewer.getElementAt(newItemIndex), 0); } } else if (e.widget == addUsingDialogButton) { Display display = Display.getCurrent(); // if it is null, get the default one display = display == null ? Display.getDefault() : display; Shell shell = display.getActiveShell(); if (kind == PATTERN) { String initialValue = ""; //$NON-NLS-1$ RegexWizard wizard = new RegexWizard(initialValue); WizardDialog wizardDialog = new WizardDialog(shell, wizard); wizardDialog.setBlockOnOpen(true); wizardDialog.create(); int result = wizardDialog.open(); if (result == Window.OK) { String newPattern = wizard.getPattern(); CompoundCommand compoundCommand = new CompoundCommand(); XSDSimpleTypeDefinition targetSimpleType = null; if (feature != null) { XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils .getAnonymousSimpleType(feature, input); if (anonymousSimpleType == null) { anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); anonymousSimpleType.setBaseTypeDefinition(input); ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand( Messages._UI_ACTION_CHANGE_PATTERN, feature); changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); compoundCommand.add(changeToAnonymousCommand); input = anonymousSimpleType; } targetSimpleType = anonymousSimpleType; } else { targetSimpleType = input; } UpdateXSDPatternFacetCommand command = new UpdateXSDPatternFacetCommand( Messages._UI_ACTION_ADD_PATTERN, targetSimpleType, UpdateXSDPatternFacetCommand.ADD); command.setValue(newPattern); setInput(input); compoundCommand.add(command); commandStack.execute(compoundCommand); facetSection.doSetInput(); } constraintsTableViewer.refresh(); } else { EnumerationsDialog dialog = new EnumerationsDialog(shell); dialog.setBlockOnOpen(true); int result = dialog.open(); if (result == Window.OK) { String text = dialog.getText(); String delimiter = dialog.getDelimiter(); StringTokenizer tokenizer = new StringTokenizer(text, delimiter); CompoundCommand compoundCommand = new CompoundCommand(Messages._UI_ACTION_ADD_ENUMERATIONS); XSDSimpleTypeDefinition targetSimpleType = null; if (feature != null) { XSDSimpleTypeDefinition anonymousSimpleType = XSDCommonUIUtils .getAnonymousSimpleType(feature, input); if (anonymousSimpleType == null) { anonymousSimpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition(); anonymousSimpleType.setBaseTypeDefinition(input); ChangeToLocalSimpleTypeCommand changeToAnonymousCommand = new ChangeToLocalSimpleTypeCommand( "", feature); //$NON-NLS-1$ changeToAnonymousCommand.setAnonymousSimpleType(anonymousSimpleType); compoundCommand.add(changeToAnonymousCommand); input = anonymousSimpleType; } targetSimpleType = anonymousSimpleType; } else { targetSimpleType = input; } while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (dialog.isPreserveWhitespace() == false) { token = token.trim(); } AddEnumerationsCommand command = new AddEnumerationsCommand( Messages._UI_ACTION_ADD_ENUMERATIONS, targetSimpleType); command.setValue(token); compoundCommand.add(command); } commandStack.execute(compoundCommand); } //setInput(input); facetSection.doSetInput(); constraintsTableViewer.refresh(); } } else if (e.widget == deleteButton) { StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection(); CompoundCommand compoundCommand = new CompoundCommand(); if (selection != null) { Iterator i = selection.iterator(); if (selection.size() > 0) { compoundCommand.setLabel(Messages._UI_ACTION_DELETE_CONSTRAINTS); } else { compoundCommand.setLabel(Messages._UI_ACTION_DELETE_PATTERN); } while (i.hasNext()) { Object obj = i.next(); if (obj != null) { if (obj instanceof XSDPatternFacet) { UpdateXSDPatternFacetCommand command = new UpdateXSDPatternFacetCommand("", input, //$NON-NLS-1$ UpdateXSDPatternFacetCommand.DELETE); command.setPatternToEdit((XSDPatternFacet) obj); compoundCommand.add(command); } else if (obj instanceof XSDEnumerationFacet) { XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) obj; DeleteCommand deleteCommand = new DeleteCommand(Messages._UI_ACTION_DELETE_ENUMERATION, enumFacet); compoundCommand.add(deleteCommand); } } } commandStack.execute(compoundCommand); constraintsTableViewer.refresh(); } } else if (e.widget == editButton) { StructuredSelection selection = (StructuredSelection) constraintsTableViewer.getSelection(); if (selection != null) { Object obj = selection.getFirstElement(); if (obj instanceof XSDPatternFacet) { XSDPatternFacet pattern = (XSDPatternFacet) obj; String initialValue = pattern.getLexicalValue(); if (initialValue == null) { initialValue = ""; //$NON-NLS-1$ } Shell shell = Display.getCurrent().getActiveShell(); RegexWizard wizard = new RegexWizard(initialValue); WizardDialog wizardDialog = new WizardDialog(shell, wizard); wizardDialog.setBlockOnOpen(true); wizardDialog.create(); int result = wizardDialog.open(); if (result == Window.OK) { String newPattern = wizard.getPattern(); pattern.setLexicalValue(newPattern); constraintsTableViewer.refresh(); } } } } setButtonStates(this.kind); }
From source file:org.eclipse.zest.tests.jface.GraphJFaceSnippet4.java
License:Open Source License
/** * @param args//from w w w . ja v a2s. co m */ public static void main(String[] args) { Display d = new Display(); Shell shell = new Shell(d); shell.setText("GraphJFaceSnippet2"); shell.setLayout(new FillLayout(SWT.VERTICAL)); shell.setSize(400, 400); viewer = new GraphViewer(shell, SWT.NONE); viewer.setContentProvider(new MyContentProvider()); viewer.setLabelProvider(new MyLabelProvider()); viewer.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING)); viewer.setInput(new Object()); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { System.out.println( "Selection Changed: " + selectionToString((StructuredSelection) event.getSelection())); } private String selectionToString(StructuredSelection selection) { StringBuffer stringBuffer = new StringBuffer(); Iterator iterator = selection.iterator(); boolean first = true; while (iterator.hasNext()) { if (first) { first = false; } else { stringBuffer.append(" : "); } stringBuffer.append(iterator.next()); } return stringBuffer.toString(); } }); shell.open(); while (!shell.isDisposed()) { while (!d.readAndDispatch()) { d.sleep(); } } }