private boolean findTarget() { // Guess, user selects an entry in the list on the left. // Find a comparable entry in the target list... boolean found = false; int sourceIndex = wSource.getSelectionIndex(); // Skip eventhing after the bracket... String sourceStr = wSource.getItem(sourceIndex).toUpperCase(); int indexOfBracket = sourceStr.indexOf(EnterMappingDialog.STRING_ORIGIN_SEPARATOR); String sourceString = sourceStr; if (indexOfBracket >= 0) { sourceString = sourceStr.substring(0, indexOfBracket); } int length = sourceString.length(); boolean first = true; while (!found && (length >= 2 || first)) { first = false; for (int i = 0; i < wTarget.getItemCount() && !found; i++) { if (wTarget.getItem(i).toUpperCase().indexOf(sourceString.substring(0, length)) >= 0) { wTarget.setSelection(i); found = true; } } length--; } return found; }
private boolean findSource() { // Guess, user selects an entry in the list on the right. // Find a comparable entry in the source list... boolean found = false; int targetIndex = wTarget.getSelectionIndex(); // Skip eventhing after the bracket... String targetString = wTarget.getItem(targetIndex).toUpperCase(); int length = targetString.length(); boolean first = true; while (!found && (length >= 2 || first)) { first = false; for (int i = 0; i < wSource.getItemCount() && !found; i++) { if (wSource.getItem(i).toUpperCase().indexOf(targetString.substring(0, length)) >= 0) { wSource.setSelection(i); found = true; } } length--; } return found; }
public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 1; composite.setLayout(layout); setControl(composite); final List lst = new List(composite, SWT.BORDER); lst.setItems(names); lst.setLayoutData(new GridData(GridData.FILL_BOTH)); lst.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) { int sel = lst.getSelectionIndex(); // recall that we are using TRANSLATED names! calculation = (CalculationEnum) EnumHelper.getEnumByTranslatedName(CalculationEnum.values(), names[sel]); } public void widgetDefaultSelected(SelectionEvent e) {} }); lst.setSelection(0); PlatformUI.getWorkbench() .getHelpSystem() .setHelp(getControl(), "Jaspersoft.wizard"); // $NON-NLS-1$ }
private void populateVersions() { versions.add("v20080424"); // $NON-NLS-1$ versions.add("v20080516"); // $NON-NLS-1$ versions.add("v20080522"); // $NON-NLS-1$ versions.add("v20080705"); // $NON-NLS-1$ versions.setSelection(0); }
@Override protected Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(2, false); container.setLayout(gridLayout); // Initialize and populate list final List list = new List(container, SWT.NONE); list.setLayoutData(new GridData(SWT.FILL)); populateList(list); list.setSelection(0); list.setSize(10, 20); list.addSelectionListener(new SomeSelectionListener(list)); Composite selectorContainer = new Composite(container, SWT.NONE); selectorContainer.setLayout(new GridLayout(1, false)); // Add color editor Composite colorContainer = new Composite(selectorContainer, SWT.NONE); color = new ColorFieldEditor(SYNTAXCOLOR_COLOR + SYNTAXCOLOR_KEYWORD, "Color", colorContainer); // Create and add style group Group styleContainer = new Group(selectorContainer, SWT.NONE); styleContainer.setText("Style"); GridLayout gridLayout2 = new GridLayout(1, false); styleContainer.setLayout(gridLayout2); Composite styleBoldContainer = new Composite(styleContainer, SWT.NONE); Composite styleItalicContainer = new Composite(styleContainer, SWT.NONE); Composite styleUnderlineContainer = new Composite(styleContainer, SWT.NONE); Composite styleStrikethroughContainer = new Composite(styleContainer, SWT.NONE); styleBold = new BooleanFieldEditor(SYNTAXCOLOR_BOLD + SYNTAXCOLOR_KEYWORD, "Bold", styleBoldContainer); styleItalic = new BooleanFieldEditor( SYNTAXCOLOR_ITALIC + SYNTAXCOLOR_KEYWORD, "Italic", styleItalicContainer); styleUnderline = new BooleanFieldEditor( SYNTAXCOLOR_UNDERLINE + SYNTAXCOLOR_KEYWORD, "Underline", styleUnderlineContainer); styleStrikethrough = new BooleanFieldEditor( SYNTAXCOLOR_STRIKETHROUGH + SYNTAXCOLOR_KEYWORD, "Strike through", styleStrikethroughContainer); // Link editors with the default preferenceStore color.setPreferenceStore(getDefaultPreferenceStore()); styleBold.setPreferenceStore(getDefaultPreferenceStore()); styleItalic.setPreferenceStore(getDefaultPreferenceStore()); styleUnderline.setPreferenceStore(getDefaultPreferenceStore()); styleStrikethrough.setPreferenceStore(getDefaultPreferenceStore()); // Load values for keyword updateEditors(SYNTAXCOLOR_KEYWORD); return container; }
@Override public void setSelection(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection sel = (StructuredSelection) selection; if (sel.isEmpty()) productTypeGUIList.setSelection(-1); else { ProductType spi = (ProductType) sel.getFirstElement(); int idx = 0; for (Iterator it = productTypeItemList.iterator(); it.hasNext(); ++idx) { ProductType pi = (ProductType) it.next(); if (spi.getPrimaryKey().equals(pi.getPrimaryKey())) { productTypeGUIList.setSelection(idx); break; } } } } }
private void addRepositoryList() { java.util.List<GuvnorRepository> reps = Activator.getLocationManager().getRepositories(); for (int i = 0; i < reps.size(); i++) { repLocations.add(reps.get(i).getLocation()); } if (repLocations.getItemCount() > 0) { repLocations.setSelection(0); updateModel(); } }
protected void refreshValidState() { super.refreshValidState(); int defaultIndex = LocalizedPropertiesPlugin.getDefault() .getPreferenceStore() .getInt(PreferenceConstants.WILDCARD_PATH_DEFAULT_INDEX_PREFERENCES); listControl.setSelection(defaultIndex); listControl.showSelection(); defaultButton.setEnabled(false); }
private void loadConsoles() { for (IConsole console : consoles) { if ((console instanceof TextConsole) && !(console instanceof GrepConsole)) { TextConsole textConsole = (TextConsole) console; consoleList.add(textConsole.getName()); } } consoleList.setSelection(0); }
void createPopup(String[] items, int selectionIndex) { // create shell and list popup = new AlphaDialog(getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.BORDER); popup.setBackgroundMode(SWT.INHERIT_DEFAULT); Color borderColor = ColorCache.getInstance().getColor(200, 200, 200); popup.setBackground(borderColor); GridLayout gridLayout = new GridLayout(2, false); gridLayout.marginHeight = 0; gridLayout.marginBottom = 1; gridLayout.marginTop = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.horizontalSpacing = 0; gridLayout.verticalSpacing = 0; gridLayout.marginWidth = 0; popup.getPopup().setLayout(gridLayout); int style = getStyle(); int listStyle = SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER; if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT; if ((style & SWT.RIGHT_TO_LEFT) != 0) listStyle |= SWT.RIGHT_TO_LEFT; if ((style & SWT.LEFT_TO_RIGHT) != 0) listStyle |= SWT.LEFT_TO_RIGHT; list = new List(popup.getPopup(), listStyle); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 2; list.setLayoutData(gridData); list.addMouseListener( new MouseAdapter() { public void mouseDown(MouseEvent e) { if (e.button == 3) { text.getMenu().setVisible(true); } if (list.isFocusControl()) return; text.forceFocus(); list.setFocus(); } }); if (font != null) list.setFont(font); if (foreground != null) list.setForeground(foreground); if (background != null) list.setBackground(background); int[] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate}; for (int i = 0; i < popupEvents.length; i++) popup.getPopup().addListener(popupEvents[i], listener); int[] listEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose }; for (int i = 0; i < listEvents.length; i++) list.addListener(listEvents[i], listener); if (items != null) list.setItems(items); if (selectionIndex != -1) list.setSelection(selectionIndex); }
/** Sets the template options in the passed list (swt) */ private void fillTemplateOptions(TemplatePersistenceData[] templateData, List list) { nameToTemplateData = new TreeMap<String, TemplatePersistenceData>(); for (TemplatePersistenceData data : templateData) { if (PyContextType.PY_MODULES_CONTEXT_TYPE.equals(data.getTemplate().getContextTypeId())) { String name = data.getTemplate().getName(); nameToTemplateData.put(name, data); } } ArrayList<String> lst = new ArrayList<String>(nameToTemplateData.keySet()); list.setItems(lst.toArray(new String[lst.size()])); list.setSelection(0); }
private void setData() { chkSegmentSource.setSelection(params.segmentSource); edSourceSRX.setText(params.getSourceSrxPath()); chkSegmentTarget.setSelection(params.segmentTarget); edTargetSRX.setText(params.getTargetSrxPath()); chkCopySource.setSelection(params.copySource); chkCheckSegments.setSelection(params.checkSegments); chkForceSegmentedOutput.setSelection(params.getForcesegmentedOutput()); listBehaviorForSegmented.setSelection(params.getSegmentationStrategy().ordinal()); updateSourceDisplay(); updateTargetDisplay(); updateOptionsDisplay(); }
/** * Displays the page at the given index. * * @param index An index between 0 and {@link #mPages}'s length - 1. */ private void displayPage(int index) { Composite page = mPages.get(index); if (page != null) { mStackLayout.topControl = page; mPagesRootComposite.layout(true); if (!mInternalPageChange) { mInternalPageChange = true; mPageList.setSelection(index); mInternalPageChange = false; } } }
/** * Moves the currently selected item up or down. * * @param up <code>true</code> if the item should move up, and <code>false</code> if it should * move down */ private void swap(boolean up) { setPresentsDefaultValue(false); int index = list.getSelectionIndex(); int target = up ? index - 1 : index + 1; if (index >= 0) { String[] selection = list.getSelection(); Assert.isTrue(selection.length == 1); list.remove(index); list.add(selection[0], target); list.setSelection(target); } selectionChanged(); }
/** * Sets the contents of the receiver's text field to the given string. * * <p>Note: The text field in a <code>Combo</code> is typically only capable of displaying a * single line of text. Thus, setting the text to a string containing line breaks or other special * characters will probably cause it to display incorrectly. * * @param string the new text * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setText(String string) { checkWidget(); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); int index = list.indexOf(string); if (index == -1) { list.deselectAll(); text.setText(string); return; } text.setText(string); text.selectAll(); list.setSelection(index); list.showSelection(); }
/** Overrides the dialog box. Prompts the user for what features to select. */ @Override protected Control createDialogArea(Composite parent) { // The composite for the dialog box Composite independentVarSelection = (Composite) super.createDialogArea(parent); independentVarSelection.setLayout(new GridLayout(1, true)); independentVarSelection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); // Checks that a list of features was set for the user to select from if (featureList != null) { // Label to prompt the user to select an X and a Y Label headerLabel = new Label(independentVarSelection, SWT.FILL); headerLabel.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false)); headerLabel.setText( "Select independent variables for " + source + "\n(Ctrl-click to select multiple)"); // The list for the X features final List independentFeatureList = new List(independentVarSelection, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL | SWT.MULTI); independentFeatureList.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false)); for (String feature : featureList) { independentFeatureList.add(feature); } // The listener for the xFeatureList which sets what the user // selected to xAxisFeature independentFeatureList.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { independentVariables.clear(); String[] selection = independentFeatureList.getSelection(); for (int i = 0; i < selection.length; i++) { independentVariables.add(selection[i]); } } }); // Select the first item by default. if (!featureList.isEmpty()) { independentFeatureList.setSelection(0); independentVariables.add(featureList.get(0)); } } return independentVarSelection; }
/** * Once the UI has been created, initializes the content. This creates the pages, selects the * first one, setup sources and scan for local folders. * * <p>Returns true if we should show the window. */ private boolean postCreate() { mUpdaterData.setWindowShell(getShell()); mTaskFactory = new ProgressTaskFactory(getShell()); mUpdaterData.setTaskFactory(mTaskFactory); mUpdaterData.setImageFactory(new ImageFactory(getShell().getDisplay())); setWindowImage(mAndroidSdkUpdater); addPage(mAvdManagerPage, "Virtual devices"); addPage(mLocalPackagePage, "Installed packages"); addPage(mRemotePackagesPage, "Available packages"); addExtraPages(); int pageIndex = 0; int i = 0; for (Composite p : mPages) { if (p.getClass().equals(mInitialPage)) { pageIndex = i; break; } i++; } displayPage(pageIndex); mPageList.setSelection(pageIndex); setupSources(); initializeSettings(); if (mUpdaterData.checkIfInitFailed()) { return false; } mUpdaterData.broadcastOnSdkLoaded(); if (mRequestAutoUpdate) { mUpdaterData.updateOrInstallAll_WithGUI( null /*selectedArchives*/, false /* includeObsoletes */); } return true; }
void listEvent(Event event) { switch (event.type) { case SWT.Dispose: if (getShell() != popup.getParent()) { String[] items = list.getItems(); int selectionIndex = list.getSelectionIndex(); popup = null; list = null; createPopup(items, selectionIndex); } break; case SWT.FocusIn: { handleFocus(SWT.FocusIn); break; } case SWT.MouseUp: { if (event.button != 1) return; dropDown(false); break; } case SWT.Selection: { int index = list.getSelectionIndex(); if (index == -1) return; text.setText(list.getItem(index)); // text.selectAll (); list.setSelection(index); // list.forceFocus(); Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; e.doit = event.doit; notifyListeners(SWT.Selection, e); event.doit = e.doit; break; } case SWT.Traverse: { switch (event.detail) { case SWT.TRAVERSE_RETURN: case SWT.TRAVERSE_ESCAPE: case SWT.TRAVERSE_ARROW_PREVIOUS: case SWT.TRAVERSE_ARROW_NEXT: event.doit = false; break; } Event e = new Event(); e.time = event.time; e.detail = event.detail; e.doit = event.doit; e.character = event.character; e.keyCode = event.keyCode; notifyListeners(SWT.Traverse, e); event.doit = e.doit; event.detail = e.detail; break; } case SWT.KeyUp: { Event e = new Event(); e.time = event.time; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.KeyUp, e); break; } case SWT.KeyDown: { if (event.character == SWT.ESC) { // Escape key cancels popup list dropDown(false); } if ((event.stateMask & SWT.ALT) != 0 && (event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_DOWN)) { dropDown(false); } if (event.character == SWT.CR) { // Enter causes default selection dropDown(false); Event e = new Event(); e.time = event.time; e.stateMask = event.stateMask; notifyListeners(SWT.DefaultSelection, e); } // At this point the widget may have been disposed. // If so, do not continue. if (isDisposed()) break; Event e = new Event(); e.time = event.time; e.character = event.character; e.keyCode = event.keyCode; e.stateMask = event.stateMask; notifyListeners(SWT.KeyDown, e); break; } } }
/** Create the dialog area and place correctly the user interfaces widgets */ @Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); GridLayout gridLayout = new GridLayout(1, false); comp.setLayout(gridLayout); GridData gridData = new GridData(GridData.FILL_BOTH); comp.setLayoutData(gridData); Group body = new Group(comp, SWT.SHADOW_ETCHED_IN); gridLayout = new GridLayout(1, false); body.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); body.setLayoutData(gridData); Composite eventBody = new Composite(body, SWT.FILL); gridLayout = new GridLayout(2, false); eventBody.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); eventBody.setLayoutData(gridData); Composite eBody = new Composite(eventBody, SWT.FILL); gridLayout = new GridLayout(2, false); eBody.setLayout(gridLayout); gridData = new GridData(GridData.FILL_VERTICAL); gridData.verticalAlignment = SWT.TOP; eBody.setLayoutData(gridData); // Events Label eventLbl = new Label(eBody, SWT.LEFT); eventLbl.setText("Event:"); eventCbx = new Combo(eBody, SWT.NONE); fillEventTypesList(); // Create a new Event if (event == null) { event = createEvent(eventCbx.getItem(0)); } else { // We need to copy the original event in case the user cancels his changes event = WidgetCopier.copy(event); } eventCbx.setText(event.getEventName()); eventCbx.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String eventName = ((Combo) e.getSource()).getText(); event.setEventName(eventName); createProperties(); // DS-3322 - Page Designer - Refactoring - begin // event.eAdapters().remove(localizable); // localizable = (Localizable) // EventLocalizableAdapterFactory.INSTANCE.adapt(event, Localizable.class); // editor.setLocalizable(localizable); // editor.setReadOnly(isReadOnly(widget)); // DS-3322 - Page Designer - Refactoring - end fillFunctionsList(); String selection = null; if (fctList.getSelection().length > 0) selection = fctList.getSelection()[0]; refreshParamControl(selection); } }); // Functions Label functionsLbl = new Label(eBody, SWT.LEFT); functionsLbl.setText("Functions:"); gridData = new GridData(); gridData.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; functionsLbl.setLayoutData(gridData); fctList = new List(eBody, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL); gridData = new GridData(GridData.FILL_VERTICAL); gridData.heightHint = 120; gridData.widthHint = 120; fctList.setLayoutData(gridData); fillFunctionsList(); fctList.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String funcName = fctList.getSelection()[0]; event.setFunctionName(funcName); createParameters(); fillParametersList(); refreshParamControl(funcName); } }); // parameters group Group paramGroup = new Group(eventBody, SWT.SHADOW_ETCHED_IN | SWT.FILL); paramGroup.setText(" Parameters "); gridLayout = new GridLayout(1, false); paramGroup.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); paramGroup.setLayoutData(gridData); userParamControl = new UserParameterControl(paramGroup, SWT.FILL); userParamControl.setInput(event, null); userParamControl.setEnabled(false); if (!StringUtils.isEmpty(event.getFunctionName())) { fctList.setSelection(new String[] {event.getFunctionName()}); refreshParamControl(event.getFunctionName()); } // attributes group Group def = new Group(body, SWT.SHADOW_ETCHED_IN); def.setText(" Attributes "); gridLayout = new GridLayout(1, false); def.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); def.setLayoutData(gridData); // Parameters table paramsTbl = new Table(def, SWT.SINGLE); gridData = new GridData(GridData.FILL_BOTH); gridData.heightHint = 100; paramsTbl.setLayoutData(gridData); paramsTbl.setHeaderVisible(true); paramsTbl.setLinesVisible(true); addColumn(paramsTbl, "Attribute", 100); addColumn(paramsTbl, "Value", 300); paramsTbl.addListener( SWT.MeasureItem, new Listener() { public void handleEvent(org.eclipse.swt.widgets.Event event) { Double dou = new Double(event.gc.getFontMetrics().getHeight() * 1.12); event.height = dou.intValue(); } }); final TableEditor paramsTblEditor = new TableEditor(paramsTbl); // The editor must have the same size as the cell and must not be any // smaller than 50 pixels. paramsTblEditor.horizontalAlignment = SWT.LEFT; paramsTblEditor.grabHorizontal = true; paramsTblEditor.grabVertical = true; paramsTblEditor.minimumWidth = 50; paramsTbl.addListener( SWT.MouseDown, new Listener() { public void handleEvent(org.eclipse.swt.widgets.Event event) { int nbColumns = paramsTbl.getColumnCount(); Rectangle clientArea = paramsTbl.getClientArea(); Point pt = new Point(event.x, event.y); int index = paramsTbl.getTopIndex(); while (index < paramsTbl.getItemCount()) { boolean visible = false; TableItem item = paramsTbl.getItem(index); for (int cx = 0; cx < nbColumns; cx++) { Rectangle rect = item.getBounds(cx); if (rect.contains(pt)) { installCellEditor(paramsTblEditor, item, index, cx); } if (!visible && rect.intersects(clientArea)) { visible = true; } } if (!visible) return; index++; } } }); fillParametersList(); def = new Group(body, SWT.SHADOW_ETCHED_IN); def.setText(" Confirmation Translations "); gridLayout = new GridLayout(1, false); def.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); def.setLayoutData(gridData); createProperties(); // DS-3322 - Page Designer - Refactoring - begin // editor = LocalizableEditorSupportFactory.createLocalizableEditor(def, 2, false, true); // localizable = (Localizable) EventLocalizableAdapterFactory.INSTANCE.adapt(event, // Localizable.class); // editor.setLocalizable(localizable); // editor.setReadOnly(isReadOnly(widget)); // addListeners(); // DS-3322 - Page Designer - Refactoring - end return comp; }
protected void updateWidget(List widget, boolean enabled) { widget.setEnabled(enabled); if (!enabled) { widget.setSelection(0); } }
@Override protected void listSetSelection(int[] ixs) { list.setSelection(ixs); }
public void setSelection(int i) { listIntermediary.setSelection(i); }