public void createControl(Composite parent) { setTitle("Keybinding"); setMessage("Insert informations for a keybinding"); Composite group = new Composite(parent, SWT.NONE); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); group.setLayout(new GridLayout(2, false)); { Label l = new Label(group, SWT.NONE); l.setText("Sequence"); keyField = new Text(group, SWT.BORDER); keyField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); keyField.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { bindtableViewer.getControl().setEnabled(isPageComplete()); setPageComplete(isPageComplete()); } }); } { Label l = new Label(group, SWT.NONE); l.setText("Binding Table"); l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); bindtableViewer = new TableViewer(group); bindtableViewer.setLabelProvider(new ComponentLabelProvider(getEditor(), Messages)); bindtableViewer.setContentProvider(new ArrayContentProvider()); bindtableViewer.setInput(application.getBindingTables()); bindtableViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { setPageComplete(isPageComplete()); } }); bindtableViewer.setSelection( new StructuredSelection(application.getBindingTables().get(0))); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = bindtableViewer.getTable().getItemHeight() * 5; bindtableViewer.getControl().setLayoutData(gd); bindtableViewer.getControl().setEnabled(false); } setControl(group); }
private <T> void findElementsRecursive( MApplicationElement searchRoot, Class<T> clazz, Selector matcher, List<T> elements, int searchFlags) { Assert.isLegal(searchRoot != null); if (searchFlags == 0) { return; } // are *we* a match ? boolean classMatch = clazz == null ? true : clazz.isInstance(searchRoot); if (classMatch && matcher.select(searchRoot)) { if (!elements.contains(searchRoot)) { @SuppressWarnings("unchecked") T element = (T) searchRoot; elements.add(element); } } if (searchRoot instanceof MApplication && (searchFlags == ANYWHERE)) { MApplication app = (MApplication) searchRoot; List<MApplicationElement> children = new ArrayList<>(); if (clazz != null) { if (clazz.equals(MHandler.class)) { children.addAll(app.getHandlers()); } else if (clazz.equals(MCommand.class)) { children.addAll(app.getCommands()); } else if (clazz.equals(MBindingContext.class)) { children.addAll(app.getBindingContexts()); } else if (clazz.equals(MBindingTable.class) || clazz.equals(MKeyBinding.class)) { children.addAll(app.getBindingTables()); } // } else { only look for these if specifically asked. // children.addAll(app.getHandlers()); // children.addAll(app.getCommands()); // children.addAll(app.getBindingContexts()); // children.addAll(app.getBindingTables()); } for (MApplicationElement child : children) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } if (searchRoot instanceof MBindingContext && (searchFlags == ANYWHERE)) { MBindingContext bindingContext = (MBindingContext) searchRoot; for (MBindingContext child : bindingContext.getChildren()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } if (searchRoot instanceof MBindingTable) { MBindingTable bindingTable = (MBindingTable) searchRoot; for (MKeyBinding child : bindingTable.getBindings()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } // Check regular containers if (searchRoot instanceof MElementContainer<?>) { /* * Bug 455281: If given a window with a primary perspective stack, * and we're not told to look outside of the perspectives (i.e., * searchFlags is missing OUTSIDE_PERSPECTIVE), then just search the * primary perspective stack instead. This ignores special areas * like the compat layer's stack holding the Help, CheatSheets, and * Intro. */ MElementContainer<?> searchContainer = (MElementContainer<?>) searchRoot; MPerspectiveStack primaryStack = null; if (searchRoot instanceof MWindow && (searchFlags & OUTSIDE_PERSPECTIVE) == 0 && (primaryStack = getPrimaryPerspectiveStack((MWindow) searchRoot)) != null) { searchContainer = primaryStack; } if (searchContainer instanceof MPerspectiveStack) { if ((searchFlags & IN_ANY_PERSPECTIVE) != 0) { // Search *all* the perspectives MElementContainer<? extends MUIElement> container = searchContainer; List<? extends MUIElement> children = container.getChildren(); for (MUIElement child : children) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } else if ((searchFlags & IN_ACTIVE_PERSPECTIVE) != 0) { // Only search the currently active perspective, if any MPerspective active = ((MPerspectiveStack) searchContainer).getSelectedElement(); if (active != null) { findElementsRecursive(active, clazz, matcher, elements, searchFlags); } } else if ((searchFlags & IN_SHARED_AREA) != 0) { // Only recurse through the shared areas List<MArea> areas = findElements(searchContainer, null, MArea.class, null); for (MArea area : areas) { findElementsRecursive(area, clazz, matcher, elements, searchFlags); } } } else { @SuppressWarnings("unchecked") MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) searchRoot; List<MUIElement> children = container.getChildren(); for (MUIElement child : children) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } } // Search Trim if (searchRoot instanceof MTrimmedWindow && (searchFlags & IN_TRIM) != 0) { MTrimmedWindow tw = (MTrimmedWindow) searchRoot; List<MTrimBar> bars = tw.getTrimBars(); for (MTrimBar bar : bars) { findElementsRecursive(bar, clazz, matcher, elements, searchFlags); } } // Search Detached Windows if (searchRoot instanceof MWindow) { MWindow window = (MWindow) searchRoot; for (MWindow dw : window.getWindows()) { findElementsRecursive(dw, clazz, matcher, elements, searchFlags); } MMenu menu = window.getMainMenu(); if (menu != null && (searchFlags & IN_MAIN_MENU) != 0) { findElementsRecursive(menu, clazz, matcher, elements, searchFlags); } // Check for Handlers if (searchFlags == ANYWHERE && MHandler.class.equals(clazz)) { for (MHandler child : window.getHandlers()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } } if (searchRoot instanceof MPerspective) { MPerspective persp = (MPerspective) searchRoot; for (MWindow dw : persp.getWindows()) { findElementsRecursive(dw, clazz, matcher, elements, searchFlags); } } // Search shared elements if (searchRoot instanceof MPlaceholder) { MPlaceholder ph = (MPlaceholder) searchRoot; // Don't search in shared areas unless the flag is set if (ph.getRef() != null && (!(ph.getRef() instanceof MArea) || (searchFlags & IN_SHARED_AREA) != 0)) { findElementsRecursive(ph.getRef(), clazz, matcher, elements, searchFlags); } } if (searchRoot instanceof MPart && (searchFlags & IN_PART) != 0) { MPart part = (MPart) searchRoot; for (MMenu menu : part.getMenus()) { findElementsRecursive(menu, clazz, matcher, elements, searchFlags); } MToolBar toolBar = part.getToolbar(); if (toolBar != null) { findElementsRecursive(toolBar, clazz, matcher, elements, searchFlags); } if (MHandler.class.equals(clazz)) { for (MHandler child : part.getHandlers()) { findElementsRecursive(child, clazz, matcher, elements, searchFlags); } } } }
@Override public boolean performFinish() { MCommand command = CommandsFactoryImpl.eINSTANCE.createCommand(); MHandler handler = CommandsFactoryImpl.eINSTANCE.createHandler(); MKeyBinding keyBinding = null; String parentId = application.getElementId(); String prefix = parentId != null && parentId.trim().length() > 0 ? parentId + "." : ""; //$NON-NLS-1$ //$NON-NLS-2$ if (handlerPage.idField.getText().trim().length() > 0) { command.setElementId( prefix + "commands." + handlerPage.idField.getText().trim()); // $NON-NLS-1$ handler.setElementId( prefix + "handlers." + handlerPage.idField.getText().trim()); // $NON-NLS-1$ } if (application.getBindingTables().size() != 0) { if (keyPage.keyField.getText().trim().length() > 0 && !keyPage.bindtableViewer.getSelection().isEmpty()) { keyBinding = CommandsFactoryImpl.eINSTANCE.createKeyBinding(); keyBinding.setKeySequence(keyPage.keyField.getText().trim()); keyBinding.setCommand(command); } } command.setCommandName(handlerPage.nameField.getText()); handler.setCommand(command); CompoundCommand cmd = new CompoundCommand(); cmd.append( AddCommand.create( getEditingDomain(), application, ApplicationPackageImpl.Literals.APPLICATION__COMMANDS, command)); cmd.append( AddCommand.create( getEditingDomain(), application, CommandsPackageImpl.Literals.HANDLER_CONTAINER__HANDLERS, handler)); if (keyBinding != null) { cmd.append( AddCommand.create( getEditingDomain(), ((IStructuredSelection) keyPage.bindtableViewer.getSelection()).getFirstElement(), CommandsPackageImpl.Literals.BINDING_TABLE__BINDINGS, keyBinding)); } if (cmd.canExecute()) { getEditingDomain().getCommandStack().execute(cmd); return true; } return false; }