List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection
public StructuredSelection(List elements)
List
. From source file:com.bdaum.zoom.gps.internal.views.MapView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { this.viewParent = parent; IConfigurationElement conf = GpsActivator.findCurrentMappingSystem(); createMapComponent(parent, conf);// www. j ava 2 s . c o m makeActions(); installListeners(); contributeToActionBars(); showMap(); if (mapComponent != null) comboContributionItem.setSelection(new StructuredSelection(conf)); preferenceListener = new IEclipsePreferences.IPreferenceChangeListener() { public void preferenceChange(PreferenceChangeEvent event) { if (event.getKey().equals(PreferenceConstants.BACKGROUNDCOLOR)) { showMap(); } } }; Ui.getUi().addPreferenceChangeListener(preferenceListener); Core.getCore().addCatalogListener(new CatalogAdapter() { @Override public void assetsModified(BagChange<Asset> changes, QueryField node) { // Refresh for Undo only assetsChanged(getNavigationHistory().getSelectedAssets(), changes == null); } @Override public void catalogClosed(int mode) { if (mode != CatalogListener.SHUTDOWN && mode != CatalogListener.EMERGENCY) refresh(); } @Override public void catalogOpened(boolean newDb) { if (!parent.isDisposed()) parent.getDisplay().asyncExec(() -> { if (!parent.isDisposed()) refresh(); }); } }); updateActions(true); }
From source file:com.bdaum.zoom.lal.internal.lire.Lire.java
License:Open Source License
@Override public void performQuery(Object value, IAdaptable adaptable, String kind) { SmartCollectionImpl sm = updateQuery(null, value, adaptable, kind); if (sm != null) { IWorkbenchWindow window = adaptable.getAdapter(IWorkbenchWindow.class); if (window != null) Ui.getUi().getNavigationHistory(window).postSelection(new StructuredSelection(sm)); }//from w w w. ja va 2 s. c om }
From source file:com.bdaum.zoom.lal.internal.lire.ui.commands.TextQueryCommand.java
License:Open Source License
@Override public void run() { if (!Core.getCore().getDbManager().getMeta(true).getNoIndex()) { Shell shell = getShell();/*from w w w .j a va 2 s . co m*/ TextSearchDialog dialog = new TextSearchDialog(shell, null, null); if (dialog.open() == Window.OK) { SmartCollection collection = dialog.getResult(); Ui.getUi().getNavigationHistory(getActiveWorkbenchWindow()) .postSelection(new StructuredSelection(collection)); } } }
From source file:com.bdaum.zoom.net.communities.CommunitiesPreferencePage.java
License:Open Source License
@SuppressWarnings("unused") public Control createPageContents(final Composite parent, AbstractPreferencePage parentPage) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); composite.setLayout(new GridLayout(1, false)); ((GridLayout) composite.getLayout()).verticalSpacing = 0; new Label(composite, SWT.NONE).setText(Messages.CommunitiesPreferencePage_community_descr); ExpandCollapseGroup expandCollapseGroup = new ExpandCollapseGroup(composite, SWT.NONE); CGroup group = createGroup(composite, 2, Messages.CommunitiesPreferencePage_photo_community_accounts); accountViewer = new TreeViewer(group, SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER); expandCollapseGroup.setViewer(accountViewer); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.heightHint = 200;//from w w w .j a v a 2 s. c om accountViewer.getControl().setLayoutData(layoutData); accountViewer.setContentProvider(new AccountContentProvider(accounts)); accountViewer.setLabelProvider(new AccountLabelProvider(accountViewer)); accountViewer.setComparator(ZViewerComparator.INSTANCE); UiUtilities.installDoubleClickExpansion(accountViewer); Composite buttonGroup = new Composite(group, SWT.NONE); buttonGroup.setLayoutData(new GridData(SWT.END, SWT.FILL, false, true)); buttonGroup.setLayout(new GridLayout(1, false)); newButton = createPushButton(buttonGroup, Messages.CommunitiesPreferencePage_new, Messages.CommunitiesPreferencePage_create_a_new_account); newButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) accountViewer.getSelection(); Object firstElement = selection.getFirstElement(); if (firstElement instanceof IConfigurationElement) { IConfigurationElement conf = (IConfigurationElement) firstElement; CommunityApi communitiesApi = CommunitiesActivator.getCommunitiesApi(conf); String id = conf.getAttribute("id"); //$NON-NLS-1$ List<CommunityAccount> list = accounts.get(id); IConfigurationElement config = conf.getChildren()[0]; EditCommunityAccountDialog dialog = new EditCommunityAccountDialog(parent.getShell(), new CommunityAccount(config), communitiesApi); if (dialog.open() == Window.OK) { CommunityAccount result = dialog.getResult(); list.add(result); setViewerInput(); accountViewer.setSelection(new StructuredSelection(result)); } } } }); editButton = createPushButton(buttonGroup, Messages.CommunitiesPreferencePage_edit, Messages.CommunitiesPreferencePage_edit_selected_account); editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) accountViewer.getSelection(); Object firstElement = selection.getFirstElement(); if (firstElement instanceof CommunityAccount) { final CommunityAccount account = (CommunityAccount) firstElement; IConfigurationElement conf = (IConfigurationElement) account.getConfiguration().getParent(); final CommunityApi communitiesApi = CommunitiesActivator.getCommunitiesApi(conf); BusyIndicator.showWhile(e.display, () -> { EditCommunityAccountDialog dialog = new EditCommunityAccountDialog(parent.getShell(), account, communitiesApi); if (dialog.open() == Window.OK) { CommunityAccount result = dialog.getResult(); accountViewer.update(result, null); changed.add(result.getCommunityId()); } }); } } }); new Label(buttonGroup, SWT.SEPARATOR | SWT.HORIZONTAL); removeButton = createPushButton(buttonGroup, Messages.CommunitiesPreferencePage_remove, Messages.CommunitiesPreferencePage_remove_selected_account); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) accountViewer.getSelection(); Object firstElement = selection.getFirstElement(); if (firstElement instanceof CommunityAccount) { CommunityAccount communityAccount = (CommunityAccount) firstElement; List<CommunityAccount> acc = accounts.get(communityAccount.getCommunityId()); if (acc != null) { int i = acc.indexOf(communityAccount); CommunityAccount sibling = (i < acc.size() - 1) ? acc.get(i + 1) : (i > 0) ? acc.get(i - 1) : null; acc.remove(i); changed.add(communityAccount.getCommunityId()); setViewerInput(); if (sibling != null) accountViewer.setSelection(new StructuredSelection(sibling)); } } } }); accountViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateButtons(); validate(); } }); setViewerInput(); updateButtons(); return composite; }
From source file:com.bdaum.zoom.net.ui.internal.preferences.InternetPreferencePage.java
License:Open Source License
private void createFtpGroup(Composite parent) { CGroup group = UiUtilities.createGroup(parent, 2, Messages.InternetPreferencePage_ftp_accounts); ftpViewer = new TableViewer(group, SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER); ftpViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); ftpViewer.setContentProvider(ArrayContentProvider.getInstance()); ftpViewer.setLabelProvider(new ZColumnLabelProvider() { @Override//from www.j ava 2s .c o m public String getText(Object element) { if (element instanceof FtpAccount) return ((FtpAccount) element).getName(); return element.toString(); } }); ftpViewer.setComparator(ZViewerComparator.INSTANCE); Composite buttonGroup = new Composite(group, SWT.NONE); buttonGroup.setLayoutData(new GridData(SWT.END, SWT.FILL, false, true)); buttonGroup.setLayout(new GridLayout(1, false)); Button newButton = createPushButton(buttonGroup, Messages.InternetPreferencePage_new, Messages.InternetPreferencePage_new_tooltip); newButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { EditFtpDialog dialog = new EditFtpDialog(getShell(), new FtpAccount(), false, null); if (dialog.open() == Window.OK) { FtpAccount result = dialog.getResult(); ftpAccounts.add(result); ftpViewer.setInput(ftpAccounts); ftpViewer.setSelection(new StructuredSelection(result)); } } }); editButton = createPushButton(buttonGroup, Messages.InternetPreferencePage_edit, Messages.InternetPreferencePage_edit_tooltip); editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = ftpViewer.getStructuredSelection(); Object firstElement = selection.getFirstElement(); if (firstElement instanceof FtpAccount) { EditFtpDialog dialog = new EditFtpDialog(getShell(), (FtpAccount) firstElement, false, null); if (dialog.open() == Window.OK) { ftpViewer.update(dialog.getResult(), null); } } } }); removeButton = createPushButton(buttonGroup, Messages.InternetPreferencePage_remove, Messages.InternetPreferencePage_remove_tooltip); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Object firstElement = ftpViewer.getStructuredSelection().getFirstElement(); if (firstElement instanceof FtpAccount) { int i = ftpAccounts.indexOf(firstElement); FtpAccount sibling = (i < ftpAccounts.size() - 1) ? ftpAccounts.get(i + 1) : (i > 0) ? ftpAccounts.get(i - 1) : null; ftpAccounts.remove(i); ftpViewer.setInput(ftpAccounts); if (sibling != null) ftpViewer.setSelection(new StructuredSelection(sibling)); } } }); ftpViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateButtons(); } }); updateButtons(); }
From source file:com.bdaum.zoom.operations.internal.ImportOperation.java
License:Open Source License
@Override public IStatus execute(IProgressMonitor aMonitor, IAdaptable info) throws ExecutionException { importState.info = info;/*from ww w .j a va2 s . c o m*/ try { int n = 0; if (fileInput != null) n += fileInput.size(); if (uris != null) n += uris.length; List<StorageObject> allFiles = new ArrayList<>(n); listFiles(fileInput, uris, allFiles); if (allFiles.isEmpty() && !isSilent()) { IDbErrorHandler errorHandler = Core.getCore().getErrorHandler(); if (errorHandler != null) errorHandler.showWarning(Messages.getString("ImportOperation.file_import"), //$NON-NLS-1$ Messages.getString("ImportOperation.no_supported_file_format"), //$NON-NLS-1$ info); } importState.nFiles = allFiles.size(); if (importState.transferNeeded()) { if (allFiles.size() > 1) { final int skipPolicy = importState.getSkipPolicy(); boolean sortForSkip = skipPolicy == Constants.SKIP_RAW_IF_JPEG || skipPolicy == Constants.SKIP_JPEG_IF_RAW || importState.getExifTransferPrefix() == null; Collections.sort(allFiles, new Comparator<StorageObject>() { public int compare(StorageObject o1, StorageObject o2) { URI u1 = o1.toURI(); URI u2 = o2.toURI(); if (!sortForSkip) return u1.compareTo(u2); String p1 = u1.toString(); String p2 = u2.toString(); String e1 = ""; //$NON-NLS-1$ String e2 = ""; //$NON-NLS-1$ int q = p1.lastIndexOf('/'); int p = p1.lastIndexOf('.'); if (p > q) { e1 = p1.substring(p); p1 = p1.substring(0, p); } q = p2.lastIndexOf('/'); p = p2.lastIndexOf('.'); if (p > q) { e2 = p2.substring(p); p2 = p2.substring(0, p); } int ret = p1.compareTo(p2); if (ret != 0) return ret; if (ImageConstants.isJpeg(e1)) return skipPolicy == Constants.SKIP_RAW_IF_JPEG ? -1 : 1; if (ImageConstants.isJpeg(e2)) return skipPolicy == Constants.SKIP_RAW_IF_JPEG ? 1 : -1; return e1.compareTo(e2); } }); } } final Meta meta = dbManager.getMeta(true); if (!allFiles.isEmpty()) { int work = IMediaSupport.IMPORTWORKSTEPS * allFiles.size(); final boolean userImport = importState.isUserImport(); if (userImport || meta.getCumulateImports()) { init(aMonitor, work + 1); cal.setTime(meta.getLastImport()); int year = cal.get(Calendar.YEAR); meta.setLastImport(importState.importDate); cal.setTime(importState.importDate); if (year != cal.get(Calendar.YEAR)) meta.setLastYearSequenceNo(0); boolean tetheredShootingActive = CoreActivator.getDefault().isTetheredShootingActive(); final String description = createImportDescription(userImport, tetheredShootingActive); if (storeSafely(() -> { previousImport = dbManager.createLastImportCollection(importState.importDate, !userImport, description, tetheredShootingActive); dbManager.store(meta); }, 1)) fireStructureModified(); } else init(aMonitor, work); importFiles(aMonitor, allFiles, info); List<Object> toBeStored = new ArrayList<Object>(); if (foldersToWatch != null && meta.getAutoWatch()) updateWatchedFolders(meta, toBeStored); if (importState.transferNeeded() && fileInput.size() > 0 && (lastDeviceImportDate != null || lastDevicePath != null)) { String key = importState.fromTransferFolder() ? null : importState.isMedia() ? fileInput.getVolume() : fileInput.getAbsolutePath(); if (key != null) { if (meta.getLastDeviceImport() == null) meta.setLastDeviceImport(new HashMap<String, LastDeviceImport>()); LastDeviceImport lastImport = meta.getLastDeviceImport(key); if (lastImport == null) meta.putLastDeviceImport(lastImport = new LastDeviceImportImpl(key, lastDeviceImportDate == null ? 0L : lastDeviceImportDate.getTime(), null, null, lastDevicePath, null, null, null, null, null, null, null, null, null, null)); else { lastImport.setTimestamp( lastDeviceImportDate == null ? 0L : lastDeviceImportDate.getTime()); lastImport.setPath(lastDevicePath); } toBeStored.add(lastImport); } } toBeStored.add(meta); if (storeSafely(null, 1, toBeStored.toArray())) { fireAssetsModified(null, null); if (importState.showImported()) { SmartCollectionImpl coll = dbManager.obtainById(SmartCollectionImpl.class, Constants.LAST_IMPORT_ID); if (coll != null) fireCatalogSelection(new StructuredSelection(coll), true); } } } else init(aMonitor, 0); } finally { if (importState.removeMedia() && fileInput.size() > 0) try { BatchUtilities.ejectMedia(fileInput.getAbsolutePath()); final IDbErrorHandler errorHandler = Core.getCore().getErrorHandler(); if (errorHandler != null) errorHandler.showInformation(Constants.APPLICATION_NAME, Messages.getString("ImportOperation.media_have_been_ejected"), //$NON-NLS-1$ info); } catch (IOException e) { addWarning(Messages.getString("ImportOperation.io_error_ejecting"), e); //$NON-NLS-1$ } importState.importFinished(); } return close(info); }
From source file:com.bdaum.zoom.peer.internal.preferences.PeerPreferencePage.java
License:Open Source License
@SuppressWarnings("unused") private Control createPeerGroup(CTabFolder parent) { Composite comp = new Composite(parent, SWT.NONE); comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); comp.setLayout(new GridLayout(1, false)); Composite innerComp = new Composite(comp, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginWidth = 0;// www. j av a 2 s.co m layout.marginHeight = 20; innerComp.setLayout(layout); innerComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Label label = new Label(innerComp, SWT.WRAP); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1)); label.setText(Messages.PeerPreferencePage_network_geography); peerViewer = new TableViewer(innerComp, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL); peerViewer.getTable().setLinesVisible(true); peerViewer.getTable().setHeaderVisible(true); peerViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); TableViewerColumn col0 = new TableViewerColumn(peerViewer, SWT.NONE); col0.getColumn().setWidth(100); col0.getColumn().setText(Messages.PeerPreferencePage_nickname); col0.setLabelProvider(new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof PeerDefinition) { String nick = ((PeerDefinition) element).getNickname(); return nick == null ? "" : nick; //$NON-NLS-1$ } return ""; //$NON-NLS-1$ } }); EditingSupport editingSupport = new EditingSupport(peerViewer) { @Override protected void setValue(Object element, Object value) { if (element instanceof PeerDefinition && value instanceof PeerDefinition) { ((PeerDefinition) element).setHost(((PeerDefinition) value).getHost()); ((PeerDefinition) element).setNickname(((PeerDefinition) value).getNickname()); ((PeerDefinition) element).setPort(((PeerDefinition) value).getPort()); peerViewer.update(element, null); } } @Override protected Object getValue(Object element) { if (element instanceof PeerDefinition) return element; return null; } @Override protected CellEditor getCellEditor(final Object element) { if (element instanceof PeerDefinition) { return new DialogCellEditor(peerViewer.getTable()) { @Override protected Object openDialogBox(Control cellEditorWindow) { PeerDefinitionDialog dialog = new PeerDefinitionDialog(cellEditorWindow.getShell(), (PeerDefinition) element, true, false, false); if (dialog.open() == Window.OK) return dialog.getResult(); return null; } }; } return null; } @Override protected boolean canEdit(Object element) { return true; } }; col0.setEditingSupport(editingSupport); TableViewerColumn col1 = new TableViewerColumn(peerViewer, SWT.NONE); col1.getColumn().setWidth(250); col1.getColumn().setText(Messages.PeerPreferencePage_peer_location); col1.setLabelProvider(new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof PeerDefinition) return ((PeerDefinition) element).getLocation(); return ""; //$NON-NLS-1$ } }); col1.setEditingSupport(editingSupport); TableViewerColumn col2 = new TableViewerColumn(peerViewer, SWT.NONE); col2.getColumn().setWidth(150); col2.getColumn().setText(Messages.PeerPreferencePage_status); col2.setLabelProvider(new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof PeerDefinition) return PeerActivator.getDefault().isOnline((PeerDefinition) element) ? Messages.PeerPreferencePage_online : Messages.PeerPreferencePage_offline; return ""; //$NON-NLS-1$ } }); peerViewer.setContentProvider(ArrayContentProvider.getInstance()); new SortColumnManager(peerViewer, new int[] { SWT.UP, SWT.UP, SWT.NONE }, 0); peerViewer.setComparator(ZViewerComparator.INSTANCE); Composite buttonGroup = new Composite(innerComp, SWT.NONE); buttonGroup.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, true)); buttonGroup.setLayout(new GridLayout()); Button addButton = new Button(buttonGroup, SWT.PUSH); addButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); addButton.setText(Messages.PeerPreferencePage_add); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { PeerDefinitionDialog dialog = new PeerDefinitionDialog(getShell(), null, true, false, false); if (dialog.open() == PeerDefinitionDialog.OK) { PeerDefinition newPeer = dialog.getResult(); @SuppressWarnings("unchecked") List<PeerDefinition> peers = (List<PeerDefinition>) peerViewer.getInput(); peers.add(newPeer); peerViewer.setInput(peers); peerViewer.setSelection(new StructuredSelection(newPeer)); } } }); final Button removeButton = new Button(buttonGroup, SWT.PUSH); removeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); removeButton.setText(Messages.PeerPreferencePage_remove); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection sel = peerViewer.getStructuredSelection(); Object firstElement = sel.getFirstElement(); if (firstElement instanceof PeerDefinition) { @SuppressWarnings("unchecked") List<PeerDefinition> peers = (List<PeerDefinition>) peerViewer.getInput(); peers.remove(firstElement); peerViewer.setInput(peers); } } }); removeButton.setEnabled(false); peerViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { removeButton.setEnabled(!event.getSelection().isEmpty()); } }); return comp; }
From source file:com.bdaum.zoom.peer.internal.preferences.PeerPreferencePage.java
License:Open Source License
@SuppressWarnings("unused") private Control createSharedGroup(CTabFolder parent) { Composite comp = new Composite(parent, SWT.NONE); comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); comp.setLayout(new GridLayout()); Composite innerComp = new Composite(comp, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginWidth = 0;/*from ww w .ja v a 2 s . com*/ layout.marginHeight = 20; innerComp.setLayout(layout); innerComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Label label = new Label(innerComp, SWT.WRAP); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1)); label.setText(Messages.PeerPreferencePage_shared_cats_msg); catViewer = new TreeViewer(innerComp, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL); catViewer.getTree().setLinesVisible(true); catViewer.getTree().setHeaderVisible(true); catViewer.getTree().setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true)); TreeViewerColumn col1 = new TreeViewerColumn(catViewer, SWT.NONE); col1.getColumn().setWidth(400); col1.getColumn().setText(Messages.PeerPreferencePage_path); col1.setLabelProvider(ZColumnLabelProvider.getDefaultInstance()); TreeViewerColumn col2 = new TreeViewerColumn(catViewer, SWT.NONE); col2.getColumn().setWidth(200); col2.getColumn().setText(Messages.PeerPreferencePage_privacy); col2.setLabelProvider(new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof SharedCatalog) return translatePrivacy(((SharedCatalog) element).getPrivacy()); if (element instanceof PeerDefinition) return ((PeerDefinition) element).getRightsLabel(); return ""; //$NON-NLS-1$ } }); col1.setEditingSupport(new EditingSupport(catViewer) { @Override protected void setValue(Object element, Object value) { if (element instanceof PeerDefinition && value instanceof PeerDefinition) { ((PeerDefinition) element).setHost(((PeerDefinition) value).getHost()); ((PeerDefinition) element).setPort(((PeerDefinition) value).getPort()); catViewer.update(element, null); validate(); } } @Override protected Object getValue(Object element) { if (element instanceof PeerDefinition) return element; return null; } @Override protected CellEditor getCellEditor(final Object element) { if (element instanceof PeerDefinition) { return new DialogCellEditor(catViewer.getTree()) { @Override protected Object openDialogBox(Control cellEditorWindow) { PeerDefinitionDialog dialog = new PeerDefinitionDialog(cellEditorWindow.getShell(), (PeerDefinition) element, true, true, true); if (dialog.open() == Window.OK) return dialog.getResult(); return null; } }; } return null; } @Override protected boolean canEdit(Object element) { return (element instanceof PeerDefinition); } }); col2.setEditingSupport(new EditingSupport(catViewer) { @Override protected void setValue(Object element, Object value) { if (element instanceof SharedCatalog && value instanceof Integer) { ((SharedCatalog) element).setPrivacy((Integer) value); catViewer.update(element, null); } else if (element instanceof PeerDefinition && value instanceof PeerDefinition) { ((PeerDefinition) element).setRights(((PeerDefinition) value).getRights()); catViewer.update(element, null); } } @Override protected Object getValue(Object element) { if (element instanceof SharedCatalog) return ((SharedCatalog) element).getPrivacy(); if (element instanceof PeerDefinition) return element; return null; } @Override protected CellEditor getCellEditor(final Object element) { if (element instanceof SharedCatalog) { ComboBoxViewerCellEditor editor = new ComboBoxViewerCellEditor(catViewer.getTree()); editor.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return translatePrivacy(((Integer) element)); } }); editor.setContentProvider(ArrayContentProvider.getInstance()); editor.setInput(((SharedCatalog) element).getRestrictions().isEmpty() ? new Integer[] { QueryField.SAFETY_RESTRICTED, QueryField.SAFETY_MODERATE, QueryField.SAFETY_SAFE, QueryField.SAFETY_LOCAL } : new Integer[] { QueryField.SAFETY_RESTRICTED, QueryField.SAFETY_MODERATE, QueryField.SAFETY_SAFE }); return editor; } if (element instanceof PeerDefinition) { return new DialogCellEditor(catViewer.getTree()) { @Override protected Object openDialogBox(Control cellEditorWindow) { PeerDefinitionDialog dialog = new PeerDefinitionDialog(cellEditorWindow.getShell(), (PeerDefinition) element, false, true, false); if (dialog.open() == Window.OK) return dialog.getResult(); return null; } @Override protected void updateContents(Object value) { if (value instanceof PeerDefinition) super.updateContents(((PeerDefinition) value).getRightsLabel()); } }; } return null; } @Override protected boolean canEdit(Object element) { return true; } }); catViewer.setContentProvider(new ITreeContentProvider() { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // do nothing } public void dispose() { // do nothing } public boolean hasChildren(Object element) { if (element instanceof SharedCatalog) return !((SharedCatalog) element).getRestrictions().isEmpty(); return false; } public Object getParent(Object element) { if (element instanceof PeerDefinition) return ((PeerDefinition) element).getParent(); return null; } public Object[] getElements(Object inputElement) { if (inputElement instanceof Collection<?>) return ((Collection<?>) inputElement).toArray(); return EMPTY; } public Object[] getChildren(Object parentElement) { if (parentElement instanceof SharedCatalog) return ((SharedCatalog) parentElement).getRestrictions().toArray(); return EMPTY; } }); new SortColumnManager(catViewer, new int[] { SWT.UP, SWT.NONE }, 0); catViewer.setComparator(ZViewerComparator.INSTANCE); UiUtilities.installDoubleClickExpansion(catViewer); Composite buttonGroup = new Composite(innerComp, SWT.NONE); buttonGroup.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, true)); buttonGroup.setLayout(new GridLayout()); addCurrentButton = new Button(buttonGroup, SWT.PUSH); addCurrentButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); addCurrentButton.setText(Messages.PeerPreferencePage_add_current); addCurrentButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String catFile = Core.getCore().getDbManager().getFileName(); SharedCatalog cat = new SharedCatalog(catFile, QueryField.SAFETY_RESTRICTED); @SuppressWarnings("unchecked") List<SharedCatalog> catalogs = (List<SharedCatalog>) catViewer.getInput(); catalogs.add(cat); catViewer.setInput(catalogs); catViewer.setSelection(new StructuredSelection(cat)); updateButtons(); } }); final Button addButton = new Button(buttonGroup, SWT.PUSH); addButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); addButton.setText(Messages.PeerPreferencePage_add); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); dialog.setFileName(Core.getCore().getDbManager().getFileName()); String filename = dialog.open(); if (filename != null) { SharedCatalog cat = new SharedCatalog(filename, QueryField.SAFETY_RESTRICTED); @SuppressWarnings("unchecked") List<SharedCatalog> catalogs = (List<SharedCatalog>) catViewer.getInput(); catalogs.add(cat); catViewer.setInput(catalogs); catViewer.setSelection(new StructuredSelection(cat)); } } }); addRestrictionButton = new Button(buttonGroup, SWT.PUSH); addRestrictionButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); addRestrictionButton.setText(Messages.PeerPreferencePage_add_restriction); addRestrictionButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) catViewer.getSelection(); Object firstElement = selection.getFirstElement(); if (firstElement instanceof SharedCatalog) { PeerDefinitionDialog dialog = new PeerDefinitionDialog(getControl().getShell(), null, true, true, true); if (dialog.open() == PeerDefinitionDialog.OK) { PeerDefinition result = dialog.getResult(); result.setParent((SharedCatalog) firstElement); catViewer.setInput(catViewer.getInput()); catViewer.expandToLevel(firstElement, 1); catViewer.setSelection(new StructuredSelection(result)); validate(); } } } }); removeCatButton = new Button(buttonGroup, SWT.PUSH); removeCatButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); removeCatButton.setText(Messages.PeerPreferencePage_remove); removeCatButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection sel = (IStructuredSelection) catViewer.getSelection(); Object firstElement = sel.getFirstElement(); if (firstElement instanceof SharedCatalog) { @SuppressWarnings("unchecked") List<SharedCatalog> catalogs = (List<SharedCatalog>) catViewer.getInput(); catalogs.remove(firstElement); catViewer.setInput(catalogs); validate(); updateButtons(); } } }); catViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateButtons(); } }); return comp; }
From source file:com.bdaum.zoom.report.internal.wizards.SourcePage.java
License:Open Source License
protected void fillValues() { report = ((ReportWizard) getWizard()).getReport(); nameField.setText(report.getName()); String descr = report.getDescription(); descriptionField.setText(descr == null ? "" : descr); //$NON-NLS-1$ String id = report.getSource(); SmartCollection sm = null;// ww w . j av a 2 s . co m if (id != null) sm = Core.getCore().getDbManager().obtainById(SmartCollectionImpl.class, id); if (sm != null) { sourceButtonGroup.setSelection(1); collViewer.setSelection(new StructuredSelection(sm)); } else sourceButtonGroup.setSelection(0); skipOrphansButton.setSelection(report.getSkipOrphans()); updateFields(); validatePage(); }
From source file:com.bdaum.zoom.ui.dialogs.ZListDialog.java
License:Open Source License
/** * Sets the list selection/*from w w w .j av a2 s.c o m*/ * * @param object * - object to select */ public void setSelection(Object object) { getTableViewer().setSelection(new StructuredSelection(object)); }