@SuppressWarnings({"unchecked", "rawtypes"}) private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) { if (!(selection instanceof ITreeSelection)) return EMPTY_WORKING_SET_ARRAY; ITreeSelection treeSelection = (ITreeSelection) selection; if (treeSelection.isEmpty()) return EMPTY_WORKING_SET_ARRAY; List elements = treeSelection.toList(); if (elements.size() == 1) { Object element = elements.get(0); TreePath[] paths = treeSelection.getPathsFor(element); if (paths.length != 1) return EMPTY_WORKING_SET_ARRAY; TreePath path = paths[0]; if (path.getSegmentCount() == 0) return EMPTY_WORKING_SET_ARRAY; Object candidate = path.getSegment(0); if (!(candidate instanceof IWorkingSet)) return EMPTY_WORKING_SET_ARRAY; IWorkingSet workingSetCandidate = (IWorkingSet) candidate; if (isValidWorkingSet(workingSetCandidate)) return new IWorkingSet[] {workingSetCandidate}; return EMPTY_WORKING_SET_ARRAY; } ArrayList result = new ArrayList(); for (Iterator iterator = elements.iterator(); iterator.hasNext(); ) { Object element = iterator.next(); if (element instanceof IWorkingSet && isValidWorkingSet((IWorkingSet) element)) { result.add(element); } } return (IWorkingSet[]) result.toArray(new IWorkingSet[result.size()]); }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { JoomlaGenModel genModel = null; ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof ITreeSelection) { ITreeSelection tree = (ITreeSelection) selection; if (!tree.isEmpty()) { Object element = tree.getFirstElement(); if (element instanceof JoomlaGenModel) { genModel = (JoomlaGenModel) element; JComponentGenerator.generate(genModel); } } } return null; }
protected void initGui(Composite parent) { final int gdMinimumWidth = 550; final int gdHeightHint = 200; createFilterPanel(parent); group = new Group(parent, SWT.NONE); if (getTitle() != null) { group.setText(getTitle()); } GridLayout groupOrganizationLayout = new GridLayout(1, true); group.setLayout(groupOrganizationLayout); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.minimumWidth = gdMinimumWidth; gd.heightHint = gdHeightHint; group.setLayoutData(gd); scrolledComposite = new ScrolledComposite(group, SWT.V_SCROLL); scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); scrolledComposite.setExpandHorizontal(true); innerComposite = new Composite(scrolledComposite, SWT.NONE); scrolledComposite.setContent(innerComposite); innerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); innerComposite.setLayout(new GridLayout(1, false)); if (selection != null && !selection.isEmpty()) { Iterator<T> iter = selection.iterator(); while (iter.hasNext()) { preSelectedElements.add(iter.next()); } } else if (selectedElement != null) { preSelectedElements.add(selectedElement); } checkboxMap = new HashMap<T, Button>(); addCheckboxes(); }