List of usage examples for org.eclipse.jface.viewers StructuredSelection size
@Override public int size()
From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java
License:Open Source License
void actionCsvTimeSliceExport() { // get selected time slices final StructuredSelection selection = (StructuredSelection) _sliceViewer.getSelection(); if (selection.size() == 0) { return;/* w w w . j a v a 2 s . c o m*/ } /* * get export filename */ final FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); dialog.setText(Messages.dialog_export_file_dialog_text); dialog.setFilterPath(_state.get(STATE_CSV_EXPORT_PATH)); dialog.setFilterExtensions(new String[] { Util.CSV_FILE_EXTENSION }); dialog.setFileName( net.tourbook.ui.UI.format_yyyymmdd_hhmmss(_tourData) + UI.SYMBOL_DOT + Util.CSV_FILE_EXTENSION); final String selectedFilePath = dialog.open(); if (selectedFilePath == null) { return; } final File exportFilePath = new Path(selectedFilePath).toFile(); // keep export path _state.put(STATE_CSV_EXPORT_PATH, exportFilePath.getPath()); if (exportFilePath.exists()) { if (net.tourbook.ui.UI.confirmOverwrite(exportFilePath) == false) { // don't overwrite file, nothing more to do return; } } /* * write time slices into csv file */ Writer exportWriter = null; try { exportWriter = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(selectedFilePath), UI.UTF_8)); final StringBuilder sb = new StringBuilder(); writeCSVHeader(exportWriter, sb); for (final Object selectedItem : selection.toArray()) { final int serieIndex = ((TimeSlice) selectedItem).serieIndex; // truncate buffer sb.setLength(0); // no. sb.append(Integer.toString(serieIndex + 0)); sb.append(UI.TAB); // time hh:mm:ss if (_serieTime != null) { sb.append(net.tourbook.common.UI.format_hh_mm_ss(_serieTime[serieIndex])); } sb.append(UI.TAB); // time in seconds if (_serieTime != null) { sb.append(Integer.toString(_serieTime[serieIndex])); } sb.append(UI.TAB); // distance if (_serieDistance != null) { sb.append(_nf6.format(_serieDistance[serieIndex] / 1000 / _unitValueDistance)); } sb.append(UI.TAB); // altitude if (_serieAltitude != null) { sb.append(_nf3.format(_serieAltitude[serieIndex] / _unitValueAltitude)); } sb.append(UI.TAB); // gradient if (_serieGradient != null) { sb.append(_nf3.format(_serieGradient[serieIndex])); } sb.append(UI.TAB); // pulse if (_seriePulse != null) { sb.append(_nf3.format(_seriePulse[serieIndex])); } sb.append(UI.TAB); // marker final TourMarker tourMarker = _markerMap.get(serieIndex); if (tourMarker != null) { sb.append(tourMarker.getLabel()); } sb.append(UI.TAB); // temperature if (_serieTemperature != null) { final float temperature = UI.convertTemperatureFromMetric(_serieTemperature[serieIndex]); sb.append(_nf3.format(temperature)); } sb.append(UI.TAB); // cadence if (_serieCadence != null) { sb.append(_nf3.format(_serieCadence[serieIndex])); } sb.append(UI.TAB); // speed if (_serieSpeed != null) { sb.append(_nf3.format(_serieSpeed[serieIndex])); } sb.append(UI.TAB); // pace if (_seriePace != null) { sb.append(net.tourbook.common.UI.format_hhh_mm_ss((long) _seriePace[serieIndex])); } sb.append(UI.TAB); // power if (_seriePower != null) { sb.append(_nf3.format(_seriePower[serieIndex])); } sb.append(UI.TAB); // longitude if (_serieLongitude != null) { sb.append(Double.toString(_serieLongitude[serieIndex])); } sb.append(UI.TAB); // latitude if (_serieLatitude != null) { sb.append(Double.toString(_serieLatitude[serieIndex])); } sb.append(UI.TAB); // break time if (_serieBreakTime != null) { sb.append(_serieBreakTime[serieIndex] ? 1 : 0); } sb.append(UI.TAB); // end of line sb.append(net.tourbook.ui.UI.SYSTEM_NEW_LINE); exportWriter.write(sb.toString()); } } catch (final IOException e) { e.printStackTrace(); } finally { if (exportWriter != null) { try { exportWriter.close(); } catch (final IOException e) { e.printStackTrace(); } } } }
From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java
License:Open Source License
/** * delete selected time slices/* w ww . ja va 2 s.c o m*/ * * @param isRemoveTime */ void actionDeleteTimeSlices(final boolean isRemoveTime) { // a tour with reference tours is currently not supported if (_isReferenceTourAvailable) { MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.tour_editor_dlg_delete_rows_title, Messages.tour_editor_dlg_delete_rows_message); return; } if (isRowSelectionMode() == false) { return; } // get selected time slices final StructuredSelection selection = (StructuredSelection) _sliceViewer.getSelection(); if (selection.size() == 0) { return; } final Object[] selectedTimeSlices = selection.toArray(); /* * check if time slices have a successive selection */ int lastIndex = -1; int firstIndex = -1; for (final Object selectedItem : selectedTimeSlices) { final TimeSlice timeSlice = (TimeSlice) selectedItem; if (lastIndex == -1) { // first slice firstIndex = lastIndex = timeSlice.serieIndex; } else { // 2...n slices if (lastIndex - timeSlice.serieIndex == -1) { // successive selection lastIndex = timeSlice.serieIndex; } else { MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.tour_editor_dlg_delete_rows_title, Messages.tour_editor_dlg_delete_rows_not_successive); return; } } } // check if markers are within the selection if (canDeleteMarkers(firstIndex, lastIndex) == false) { return; } /* * get first selection index to select a time slice after removal */ final Table table = (Table) _sliceViewer.getControl(); final int[] indices = table.getSelectionIndices(); Arrays.sort(indices); int lastSelectionIndex = indices[0]; TourManager.removeTimeSlices(_tourData, firstIndex, lastIndex, isRemoveTime); getDataSeriesFromTourData(); // update UI updateUI_Tab_1_Tour(); updateUI_Tab_3_Info(); // update slice viewer _sliceViewerItems = getRemainingSliceItems(_sliceViewerItems, firstIndex, lastIndex); _sliceViewer.getControl().setRedraw(false); { // update viewer _sliceViewer.remove(selectedTimeSlices); // update serie index label _sliceViewer.refresh(true); } _sliceViewer.getControl().setRedraw(true); setTourDirty(); // notify other viewers fireModifyNotification(); /* * select next available time slice */ final int itemCount = table.getItemCount(); if (itemCount > 0) { // adjust to array bounds lastSelectionIndex = Math.max(0, Math.min(lastSelectionIndex, itemCount - 1)); table.setSelection(lastSelectionIndex); table.showSelection(); // fire selection position _sliceViewer.setSelection(_sliceViewer.getSelection()); } }
From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java
License:Open Source License
/** * enable actions//from www. j a v a 2 s. c o m */ private void enableSliceActions() { final StructuredSelection sliceSelection = (StructuredSelection) _sliceViewer.getSelection(); final int numberOfSelectedSlices = sliceSelection.size(); final boolean isSliceSelected = numberOfSelectedSlices > 0; final boolean isOneSliceSelected = numberOfSelectedSlices == 1; final boolean isTourInDb = isTourInDb(); // check if a marker can be created boolean canCreateMarker = false; if (isOneSliceSelected) { final TimeSlice oneTimeSlice = (TimeSlice) sliceSelection.getFirstElement(); canCreateMarker = _markerMap.containsKey(oneTimeSlice.serieIndex) == false; } // get selected Marker TourMarker selectedMarker = null; for (final Iterator<?> iterator = sliceSelection.iterator(); iterator.hasNext();) { final TimeSlice timeSlice = (TimeSlice) iterator.next(); if (_markerMap.containsKey(timeSlice.serieIndex)) { selectedMarker = _markerMap.get(timeSlice.serieIndex); break; } } _actionCreateTourMarker.setEnabled(_isEditMode && isTourInDb && isOneSliceSelected && canCreateMarker); _actionOpenMarkerDialog.setEnabled(_isEditMode && isTourInDb); // select marker _actionOpenMarkerDialog.setTourMarker(selectedMarker); _actionDeleteTimeSlicesRemoveTime.setEnabled(_isEditMode && isTourInDb && isSliceSelected); _actionDeleteTimeSlicesKeepTime.setEnabled(_isEditMode && isTourInDb && isSliceSelected); _actionExportTour.setEnabled(true); _actionCsvTimeSliceExport.setEnabled(isSliceSelected); _actionSplitTour.setEnabled(isOneSliceSelected); _actionExtractTour.setEnabled(numberOfSelectedSlices >= 2); // set start/end position into the actions if (isSliceSelected) { final Object[] selectedSliceArray = sliceSelection.toArray(); final int lastSliceIndex = selectedSliceArray.length - 1; final TimeSlice firstSelectedTimeSlice = (TimeSlice) selectedSliceArray[0]; final TimeSlice lastSelectedTimeSlice = (TimeSlice) selectedSliceArray[lastSliceIndex]; final int firstSelectedSerieIndex = firstSelectedTimeSlice.serieIndex; final int lastSelectedSerieIndex = lastSelectedTimeSlice.serieIndex; _actionExportTour.setTourRange(firstSelectedSerieIndex, lastSelectedSerieIndex); _actionSplitTour.setTourRange(firstSelectedSerieIndex); _actionExtractTour.setTourRange(firstSelectedSerieIndex, lastSelectedSerieIndex); /* * prevent that the first and last slice is selected for the split which causes errors */ final int numberOfAllSlices = _sliceViewerItems.length; final boolean isSplitValid = firstSelectedSerieIndex > 0 && firstSelectedSerieIndex < numberOfAllSlices - 1; _actionSplitTour.setEnabled(isOneSliceSelected && isSplitValid); } }
From source file:org.adorsys.plh.pkix.workbench.navigator.internal.ResourceNavigator.java
License:Open Source License
@Inject public ResourceNavigator(Composite parent, final IEclipseContext context, IWorkspace workspace) { final Realm realm = SWTObservables.getRealm(parent.getDisplay()); this.context = context; parent.setLayout(new FillLayout()); TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectionService//w w w . j ava2s.c o m .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); // context.modify(IServiceConstants.ACTIVE_SELECTION, selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); } }); IObservableFactory setFactory = new IObservableFactory() { public IObservable createObservable(Object element) { if (element instanceof IContainer && ((IContainer) element).exists()) { IObservableSet observableSet = observableSets.get(element); if (observableSet == null) { observableSet = new WritableSet(realm); try { observableSet.addAll(Arrays.asList(((IContainer) element).members())); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } observableSets.put((IContainer) element, observableSet); } return observableSet; } return Observables.emptyObservableSet(); } }; viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() { public Boolean hasChildren(Object element) { return Boolean.valueOf(element instanceof IContainer); } })); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof IResource) return ((IResource) element).getName(); return element == null ? "" : element.toString(); } }); viewer.setSorter(new ViewerSorter()); viewer.setInput(workspace.getRoot()); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); for (Object o : s.toArray()) { if (o instanceof IFile) { IFile f = (IFile) o; context.set(IFile.class, f); String fExt = f.getFileExtension(); EDITOR: for (MPartDescriptor desc : application.getDescriptors()) { String category = desc.getCategory(); if (category == null) continue; String[] categories = category.split(","); for (String ext : categories) { if (ext.equalsIgnoreCase(fExt)) { context.set(MPartDescriptor.class, desc); System.err.println("Opening with: " + desc); Command cmd = commandService.getCommand("desktop.command.openeditor"); ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null); handlerService.executeHandler(pCmd); break EDITOR; } } } } } } }); setupContextMenu(viewer, parent.getShell()); workspace.addResourceChangeListener(listener); }
From source file:org.apache.directory.studio.apacheds.configuration.actions.OpenConfigurationAction.java
License:Apache License
/** * {@inheritDoc}/*from ww w . j a v a 2 s . c om*/ */ public void selectionChanged(IAction action, ISelection selection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if ((structuredSelection.size() == 1) && (structuredSelection.getFirstElement() instanceof Connection)) { selectedConnection = (Connection) structuredSelection.getFirstElement(); } else { selectedConnection = null; } }
From source file:org.apache.directory.studio.ldapbrowser.ui.actions.GotoDnNavigateMenuAction.java
License:Apache License
/** * Gets the currently selected connection. * * @return the currently selected connection *//*from w ww.j ava 2 s .c o m*/ private Connection getSelectedConnection() { // Getting the connections view ConnectionView connectionView = (ConnectionView) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().findView(ConnectionView.getId()); if (connectionView != null) { // Getting the selection of the connections view StructuredSelection selection = (StructuredSelection) connectionView.getMainWidget().getViewer() .getSelection(); // Checking if only one object is selected if (selection.size() == 1) { Object selectedObject = selection.getFirstElement(); // Checking if the selected object is a connection if (selectedObject instanceof Connection) { return (Connection) selectedObject; } } } return null; }
From source file:org.apache.directory.studio.ldapbrowser.ui.dialogs.preferences.EntryEditorsPreferencePage.java
License:Apache License
/** * Moves the currently selected entry editor. * * @param direction/*from ww w . ja v a 2s .co m*/ * the direction (up or down) */ private void moveSelectedEntryEditor(MoveEntryEditorDirectionEnum direction) { StructuredSelection selection = (StructuredSelection) entryEditorsTableViewer.getSelection(); if (selection.size() == 1) { EntryEditorExtension entryEditor = (EntryEditorExtension) selection.getFirstElement(); if (sortedEntryEditorsList.contains(entryEditor)) { int oldIndex = sortedEntryEditorsList.indexOf(entryEditor); int newIndex = 0; // Determining the new index number switch (direction) { case UP: newIndex = oldIndex - 1; break; case DOWN: newIndex = oldIndex + 1; break; } // Checking bounds if ((newIndex >= 0) && (newIndex < sortedEntryEditorsList.size())) { // Switching the two entry editors EntryEditorExtension newIndexEntryEditorBackup = sortedEntryEditorsList.set(newIndex, entryEditor); sortedEntryEditorsList.set(oldIndex, newIndexEntryEditorBackup); // Reloading the viewer entryEditorsTableViewer.refresh(); // Updating the state of the buttons updateButtonsState(entryEditor); // Setting the "Use User Priority" to true useUserPriority = true; } } } }
From source file:org.apache.directory.studio.ldapbrowser.ui.dialogs.preferences.EntryEditorsPreferencePage.java
License:Apache License
/** * Updates the state of the buttons.//ww w . ja va 2s .com */ private void updateButtonsState() { StructuredSelection selection = (StructuredSelection) entryEditorsTableViewer.getSelection(); if (selection.size() == 1) { EntryEditorExtension entryEditor = (EntryEditorExtension) selection.getFirstElement(); // Updating the state of the buttons updateButtonsState(entryEditor); } }
From source file:org.apache.directory.studio.ldapservers.actions.OpenConfigurationAction.java
License:Apache License
/** * {@inheritDoc}/*ww w .j a v a2s . c o m*/ */ public void run() { if (view != null) { // Getting the selection StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { // Getting the server LdapServer server = (LdapServer) selection.getFirstElement(); // Creating and scheduling the job to start the server StudioLdapServerJob job = new StudioLdapServerJob(new OpenConfigurationLdapServerRunnable(server)); job.schedule(); } } }
From source file:org.apache.directory.studio.ldapservers.actions.StartAction.java
License:Apache License
/** * {@inheritDoc}/*from w w w .j a va2 s . c o m*/ */ public void run() { if (view != null) { // Getting the selection StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection(); if ((!selection.isEmpty()) && (selection.size() == 1)) { // Getting the server LdapServer server = (LdapServer) selection.getFirstElement(); LdapServerAdapterExtension ldapServerAdapterExtension = server.getLdapServerAdapterExtension(); if ((ldapServerAdapterExtension != null) && (ldapServerAdapterExtension.getInstance() != null)) { LdapServerAdapter ldapServerAdapter = ldapServerAdapterExtension.getInstance(); try { // Getting the ports already in use String[] portsAlreadyInUse = ldapServerAdapter.checkPortsBeforeServerStart(server); if ((portsAlreadyInUse == null) || (portsAlreadyInUse.length > 0)) { String title = null; String message = null; if (portsAlreadyInUse.length == 1) { title = Messages.getString("StartAction.PortInUse"); //$NON-NLS-1$ message = NLS.bind(Messages.getString("StartAction.PortOfProtocolInUse"), //$NON-NLS-1$ new String[] { portsAlreadyInUse[0] }); } else { title = Messages.getString("StartAction.PortsInUse"); //$NON-NLS-1$ message = Messages.getString("StartAction.PortsOfProtocolsInUse"); //$NON-NLS-1$ for (String portAlreadyInUse : portsAlreadyInUse) { message += "\n - " + portAlreadyInUse; //$NON-NLS-1$ } } message += "\n\n" + Messages.getString("StartAction.Continue"); //$NON-NLS-1$ //$NON-NLS-2$ MessageDialog dialog = new MessageDialog(view.getSite().getShell(), title, null, message, MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, MessageDialog.OK); if (dialog.open() == MessageDialog.CANCEL) { return; } } // Creating and scheduling the job to start the server StudioLdapServerJob job = new StudioLdapServerJob(new StartLdapServerRunnable(server)); job.schedule(); } catch (Exception e) { // Showing an error in case no LDAP Server Adapter can be found MessageDialog.openError(view.getSite().getShell(), Messages.getString("StartAction.ErrorStartingServer"), //$NON-NLS-1$ NLS.bind( Messages.getString("StartAction.ServerCanNotBeStarted") + "\n" //$NON-NLS-1$//$NON-NLS-2$ + Messages.getString("StartAction.Cause"), //$NON-NLS-1$ server.getName(), e.getMessage())); } } else { // Showing an error in case no LDAP Server Adapter can be found MessageDialog.openError(view.getSite().getShell(), Messages.getString("StartAction.NoLdapServerAdapter"), //$NON-NLS-1$ NLS.bind(Messages.getString("StartAction.ServerCanNotBeStarted") + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + Messages.getString("StartAction.NoLdapServerAdapterCouldBeFound"), //$NON-NLS-1$ server.getName())); } } } }