List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
private void createFloorplan(Composite parent) { parent.setLayout(new GridLayout()); Composite comp = new Composite(parent, SWT.NONE); comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); comp.setLayout(new GridLayout(2, false)); Composite detailGroup = new Composite(comp, SWT.NONE); detailGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); detailGroup.setLayout(new GridLayout(2, false)); itemViewer = new ComboViewer(detailGroup); itemViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); itemViewer.setContentProvider(ArrayContentProvider.getInstance()); itemViewer.setLabelProvider(new LabelProvider() { @Override//w w w. j a v a 2s . co m public String getText(Object element) { if (element instanceof Exhibition) return Messages.ExhibitionEditDialog_entrance; if (element instanceof Wall) return ((Wall) element).getLocation(); return super.getText(element); } }); List<Object> items = new ArrayList<Object>(current.getWall().size() + 1); items.add(current); items.addAll(current.getWall()); itemViewer.setInput(items); Label xlabel = new Label(detailGroup, SWT.NONE); xlabel.setText(Messages.ExhibitionEditDialog_ground_xpos + captionUnitmft()); xspinner = new NumericControl(detailGroup, NumericControl.LOGARITHMIC); xspinner.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); xspinner.setMaximum(unit == 'i' ? 1500000 : 500000); xspinner.setIncrement(unit == 'i' ? 30 : 10); xspinner.setDigits(2); Listener listener = new Listener() { @Override public void handleEvent(Event event) { if (event.widget == xspinner) updateItems(toMm(xspinner.getSelection()), -1, Double.NaN); else if (event.widget == yspinner) updateItems(-1, toMm(yspinner.getSelection()), Double.NaN); else if (event.widget == aspinner) updateItems(-1, -1, aspinner.getSelection() / 10d); } }; xspinner.addListener(listener); Label ylabel = new Label(detailGroup, SWT.NONE); ylabel.setText(Messages.ExhibitionEditDialog_ground_ypos + captionUnitmft()); yspinner = new NumericControl(detailGroup, NumericControl.LOGARITHMIC); yspinner.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); yspinner.setMaximum(unit == 'i' ? 1500000 : 500000); yspinner.setIncrement(unit == 'i' ? 30 : 10); yspinner.setDigits(2); yspinner.addListener(listener); alabel = new Label(detailGroup, SWT.NONE); alabel.setText(Messages.ExhibitionEditDialog_ground_angle); aspinner = new NumericControl(detailGroup, SWT.NONE); aspinner.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); aspinner.setMaximum(3600); aspinner.setIncrement(10); aspinner.setDigits(1); aspinner.addListener(listener); floorplan = new Canvas(comp, SWT.DOUBLE_BUFFERED); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.widthHint = 400; data.heightHint = 300; floorplan.setLayoutData(data); floorplan.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle area = floorplan.getClientArea(); GC gc = e.gc; gc.setBackground(e.display.getSystemColor(SWT.COLOR_WHITE)); gc.fillRectangle(area); int minx = Integer.MAX_VALUE; int miny = Integer.MAX_VALUE; int maxx = Integer.MIN_VALUE; int maxy = Integer.MIN_VALUE; int n = current.getWall().size(); wxs = new int[n]; wys = new int[n]; wx2s = new int[n]; wy2s = new int[n]; double[] wa = new double[n]; int i = 0; for (Wall wall : current.getWall()) { double angle = wall.getGAngle(); int gx = wall.getGX(); int gy = wall.getGY(); boolean match = false; for (int j = 0; j < i; j++) if (gx == wxs[j] && gy == wys[j] && angle == wa[j]) { match = true; break; } if (match) { wall.setGX(wx2s[i - 1]); gx = wx2s[i - 1]; wall.setGY(wy2s[i - 1]); gy = wy2s[i - 1]; double d = wa[i - 1]; if (d > 45 && d < 135) angle = ((i / 2) % 2 == 0) ? d - 90 : d + 90; else if (d > 135 && d < 225) angle = d - 90; else angle = d + 90; if (angle < 0) angle += 360; else if (angle >= 360) angle -= 360; wall.setGAngle(angle); updateFloorplanDetails(); } int width = wall.getWidth(); double r = Math.toRadians(angle); int gx2 = (int) (gx + Math.cos(r) * width + D05); int gy2 = (int) (gy + Math.sin(r) * width + D05); minx = Math.min(minx, Math.min(gx, gx2)); miny = Math.min(miny, Math.min(gy, gy2)); maxx = Math.max(maxx, Math.max(gx, gx2)); maxy = Math.max(maxy, Math.max(gy, gy2)); wxs[i] = gx; wys[i] = gy; wx2s[i] = gx2; wy2s[i] = gy2; wa[i] = angle; ++i; } int sx = current.getStartX(); int sy = current.getStartY(); minx = Math.min(minx, sx); miny = Math.min(miny, sy); maxx = Math.max(maxx, sx); maxy = Math.max(maxy, sy); double w = maxx - minx; double h = maxy - miny; scale = Math.min(area.width / w, area.height / h) / 2d; xoff = (int) (area.width / 4 - minx * scale); yoff = (int) (area.height / 4 - miny * scale); double d = -Math.floor(xoff / (D1000 * scale)) * D1000; while (true) { int x = xoff + (int) (d * scale + D05); if (x > area.width) break; gc.setForeground(e.display.getSystemColor(d == 0d ? SWT.COLOR_BLUE : SWT.COLOR_GRAY)); gc.drawLine(x, 0, x, area.height); d += D1000; } d = -Math.floor(yoff / (D1000 * scale)) * D1000; while (true) { int y = yoff + (int) (d * scale + D05); gc.setForeground(e.display.getSystemColor(d == 0d ? SWT.COLOR_BLUE : SWT.COLOR_GRAY)); if (y > area.height) break; gc.drawLine(0, y, area.width, y); d += D1000; } gc.setBackground(e.display.getSystemColor(SWT.COLOR_GRAY)); gc.fillRectangle(xoff - 3, yoff - 3, 6, 6); gc.setLineWidth(2); Wall doorWall = null; i = 0; for (Wall wall : current.getWall()) { gc.setForeground( e.display.getSystemColor(selectedItem == wall ? SWT.COLOR_RED : SWT.COLOR_DARK_GRAY)); int x1 = xoff + (int) (wxs[i] * scale + D05); int y1 = yoff + (int) (wys[i] * scale + D05); int x2 = xoff + (int) (wx2s[i] * scale + D05); int y2 = yoff + (int) (wy2s[i] * scale + D05); gc.drawLine(x1, y1, x2, y2); double aAngle = wall.getGAngle(); double r = Math.toRadians(aAngle); double sin = Math.sin(r); double cos = Math.cos(r); if (sx >= Math.min(wxs[i], wx2s[i]) - 50 && sx <= Math.max(wxs[i], wx2s[i]) + 50 && sy >= Math.min(wys[i], wy2s[i]) - 50 && sy <= Math.max(wys[i], wy2s[i]) + 50) { if (Math.abs(cos) > 0.01d) { if (Math.abs(wys[i] - sy + (sx - wxs[i]) * sin / cos) < 50) doorWall = wall; } else doorWall = wall; } int xa = (int) ((x1 + x2) * D05 - sin * 5); int ya = (int) ((y1 + y2) * D05 + cos * 5); aAngle += 135; r = Math.toRadians(aAngle); int x3 = (int) (xa + 6 * Math.cos(r) + D05); int y3 = (int) (ya + 6 * Math.sin(r) + D05); gc.drawLine(xa, ya, x3, y3); aAngle -= 270; r = Math.toRadians(aAngle); x3 = (int) (xa + 6 * Math.cos(r) + D05); y3 = (int) (ya + 6 * Math.sin(r) + D05); gc.drawLine(xa, ya, x3, y3); ++i; } if (doorWall != null) { int lineStyle = gc.getLineStyle(); gc.setLineStyle(SWT.LINE_DASH); double r = Math.toRadians(doorWall.getGAngle()); double sin = Math.sin(r); double cos = Math.cos(r); double dx = sx * scale - sin * 5; double dy = sy * scale + cos * 5; int dx1 = (int) (dx + DOORWIDTH / 2 * scale * cos + D05); int dy1 = (int) (dy - DOORWIDTH / 2 * scale * sin + D05); int dx2 = (int) (dx - (INFOWIDTH + DOORWIDTH / 2) * scale * cos + D05); int dy2 = (int) (dy + (INFOWIDTH + DOORWIDTH / 2) * scale * sin + D05); gc.drawLine(xoff + dx1, yoff + dy1, xoff + dx2, yoff + dy2); gc.setLineStyle(lineStyle); } gc.setForeground( e.display.getSystemColor(selectedItem == current ? SWT.COLOR_RED : SWT.COLOR_DARK_GREEN)); gc.drawOval(xoff + (int) (sx * scale + D05) - ENTRANCEDIAMETER / 2 - 1, yoff + (int) (sy * scale + D05) - ENTRANCEDIAMETER / 2 - 1, ENTRANCEDIAMETER, ENTRANCEDIAMETER); } }); floorplan.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { if (hotObject != null) { dragStart = new Point(e.x, e.y); draggedObject = hotObject; dragHandle = hotIndex; hotObject = null; } } @Override public void mouseUp(MouseEvent e) { recentlyDraggedObject = draggedObject; draggedObject = null; Object sel = null; int x = e.x; int y = e.y; int sx = xoff + (int) (current.getStartX() * scale + D05); int sy = yoff + (int) (current.getStartY() * scale + D05); if (Math.sqrt((sx - x) * (sx - x) + (sy - y) * (sy - y)) <= ENTRANCEDIAMETER / 2 + 1) { sel = current; } else { int i = 0; for (Wall wall : current.getWall()) { int x1 = xoff + (int) (wxs[i] * scale + D05); int y1 = yoff + (int) (wys[i] * scale + D05); int x2 = xoff + (int) (wx2s[i] * scale + D05); int y2 = yoff + (int) (wy2s[i] * scale + D05); double d = Math.abs((x2 - x1) * (y1 - y) - (x1 - x) * (y2 - y1)) / Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); if (d < TOLERANCE && x <= Math.max(x1, x2) + TOLERANCE && x >= Math.min(x1, x2) - TOLERANCE && y <= Math.max(y1, y2) + TOLERANCE && y >= Math.min(y1, y2) - TOLERANCE) { sel = wall; break; } ++i; } } if (sel != null) itemViewer.setSelection(new StructuredSelection(sel)); } }); floorplan.addMouseMoveListener(new MouseMoveListener() { public void mouseMove(MouseEvent e) { if (draggedObject != null) { int dx = e.x - dragStart.x; int dy = e.y - dragStart.y; int x = origin.x + (int) (dx / scale + D05); int y = origin.y + (int) (dy / scale + D05); if (draggedObject == current) { current.setStartX(x); current.setStartY(y); } else if (draggedObject instanceof Wall) { Wall wall = (Wall) draggedObject; if (dragHandle == 1) { wall.setGX(x); wall.setGY(y); } else { double ddx = wall.getGX() - x; double ddy = wall.getGY() - y; double angle = ddx == 0 ? 90 : Math.toDegrees(Math.atan(ddy / ddx)); if (ddx > 0) { if (ddy < 0) angle += 180; else angle -= 180; } wall.setGAngle(angle); } } floorplan.redraw(); updateFloorplanDetails(); return; } IStructuredSelection selection = itemViewer.getStructuredSelection(); hotObject = null; hotIndex = -1; Object sel = selection.getFirstElement(); int x = e.x; int y = e.y; int sx = xoff + (int) (current.getStartX() * scale + D05); int sy = yoff + (int) (current.getStartY() * scale + D05); if (sel == current && Math.sqrt((sx - x) * (sx - x) + (sy - y) * (sy - y)) <= ENTRANCEDIAMETER / 2 + 1) { hotObject = current; origin.x = current.getStartX(); origin.y = current.getStartY(); } else { int i = 0; for (Wall wall : current.getWall()) { if (sel == wall) { int x1 = xoff + (int) (wxs[i] * scale + D05); int y1 = yoff + (int) (wys[i] * scale + D05); int x2 = xoff + (int) (wx2s[i] * scale + D05); int y2 = yoff + (int) (wy2s[i] * scale + D05); if (Math.sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)) <= TOLERANCE) { hotIndex = 1; hotObject = wall; origin.x = wxs[i]; origin.y = wys[i]; } else if (Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y)) <= TOLERANCE) { hotIndex = 2; hotObject = wall; origin.x = wx2s[i]; origin.y = wy2s[i]; } } ++i; } } if (hotObject != null) { if (hotIndex == 2) floorplan.setCursor(rotCursor); else floorplan.setCursor(getShell().getDisplay().getSystemCursor(SWT.CURSOR_SIZEALL)); } else floorplan.setCursor(getShell().getDisplay().getSystemCursor(SWT.CURSOR_ARROW)); } }); floorplan.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (recentlyDraggedObject != null) { int dx = 0; int dy = 0; switch (e.keyCode) { case SWT.ARROW_LEFT: dx = -10; break; case SWT.ARROW_RIGHT: dx = 10; break; case SWT.ARROW_UP: dy = -10; break; case SWT.ARROW_DOWN: dy = 10; break; case SWT.HOME: dx = -500; break; case SWT.END: dx = 500; break; case SWT.PAGE_UP: dy = -500; break; case SWT.PAGE_DOWN: dy = 500; break; default: return; } if (recentlyDraggedObject == current) { current.setStartX(current.getStartX() + dx); current.setStartY(current.getStartY() + dy); } else if (recentlyDraggedObject instanceof Wall) { Wall wall = (Wall) recentlyDraggedObject; int gx = wall.getGX(); int gy = wall.getGY(); if (dragHandle == 1) { wall.setGX(gx + dx); wall.setGY(gy + dy); } else { int width = wall.getWidth(); double r = Math.toRadians(wall.getGAngle()); int gx2 = (int) (gx + Math.cos(r) * width + D05); int gy2 = (int) (gy + Math.sin(r) * width + D05); double ddx = gx - gx2 - dx; double ddy = gy - gy2 - dy; double angle = ddx == 0 ? 90 : Math.toDegrees(Math.atan(ddy / ddx)); if (ddx > 0) angle = ddy < 0 ? 180 + angle : angle - 180; wall.setGAngle(angle); } } floorplan.redraw(); updateFloorplanDetails(); return; } } }); updateFloorplanDetails(); itemViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { selectedItem = ((IStructuredSelection) event.getSelection()).getFirstElement(); updateFloorplanDetails(); floorplan.redraw(); } }); itemViewer.setSelection(new StructuredSelection(current)); }
From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java
License:Open Source License
protected void updateFloorplanDetails() { IStructuredSelection selection = itemViewer.getStructuredSelection(); Object firstElement = selection.getFirstElement(); if (firstElement instanceof Wall) { Wall wall = (Wall) firstElement; xspinner.setSelection(fromMm(wall.getGX())); yspinner.setSelection(fromMm(wall.getGY())); aspinner.setSelection((int) (wall.getGAngle() * 10 + 0.5d)); aspinner.setVisible(true);// w w w . j av a 2 s . c o m alabel.setVisible(true); } else if (current != null) { xspinner.setSelection(fromMm(current.getStartX())); yspinner.setSelection(fromMm(current.getStartY())); alabel.setVisible(false); aspinner.setVisible(false); } }
From source file:com.bdaum.zoom.ui.internal.dialogs.MigrateDialog.java
License:Open Source License
private void updateButtons() { IStructuredSelection selection = viewer.getStructuredSelection(); boolean enabled = !selection.isEmpty(); removePatternButton.setEnabled(enabled); editPatternButton.setEnabled(enabled); if (enabled) { int i = rules.indexOf(selection.getFirstElement()); downButton.setEnabled(i < rules.size() - 1); upButton.setEnabled(i > 0);//from w ww. j ava 2s . co m } else { downButton.setEnabled(false); upButton.setEnabled(false); } String errorMessage = null; if (fileEditor.getText().isEmpty()) errorMessage = Messages.MigrateDialog_define_target_cat_file; else if (rules.isEmpty()) errorMessage = Messages.MigrateDialog_define_one_pattern; else { File file = new File(fileEditor.getText()); long freeSpace = Core.getCore().getVolumeManager().getRootFile(file).getUsableSpace(); long catSize = (long) (dbManager.getFile().length() * 1.05d); if (freeSpace < catSize) errorMessage = NLS.bind(Messages.MigrateDialog_not_enough_free_space, Format.sizeFormatter.toString(freeSpace), Format.sizeFormatter.toString(catSize)); } setErrorMessage(errorMessage); getButton(OK).setEnabled(errorMessage == null); getButton(SAVE).setEnabled(errorMessage == null); getButton(LOAD).setEnabled(!dbManager.obtainObjects(MigrationPolicy.class).isEmpty()); }
From source file:com.bdaum.zoom.ui.internal.dialogs.MigrateDialog.java
License:Open Source License
@Override protected void buttonPressed(int buttonId) { switch (buttonId) { case LOAD:/*w ww . j av a 2s . co m*/ if (dirty && !AcousticMessageDialog.openQuestion(getShell(), Messages.MigrateDialog_load_migration_policy, Messages.MigrateDialog_abandon_current_policy)) return; List<MigrationPolicy> set = dbManager.obtainObjects(MigrationPolicy.class); if (!set.isEmpty()) { List<MigrationPolicy> policies = new ArrayList<MigrationPolicy>(set); ListDialog dialog = new ListDialog(getShell()) { @Override public void create() { super.create(); getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateDeleteButton(); } }); } @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, 9999, Messages.MigrateDialog_remove, false); super.createButtonsForButtonBar(parent); } @Override protected void buttonPressed(int buttonId) { if (buttonId == 9999) { TableViewer tableViewer = getTableViewer(); IStructuredSelection selection = tableViewer.getStructuredSelection(); if (!selection.isEmpty()) { MigrationPolicy policy = (MigrationPolicy) selection.getFirstElement(); tableViewer.remove(policy); List<Object> toBeDeleted = new ArrayList<Object>(policy.getRule().length + 1); toBeDeleted.addAll(Arrays.asList(policy.getRule())); toBeDeleted.add(policy); dbManager.safeTransaction(toBeDeleted, null); updateDeleteButton(); return; } } else super.buttonPressed(buttonId); } private void updateDeleteButton() { getButton(9999).setEnabled(!getTableViewer().getSelection().isEmpty()); } }; dialog.setContentProvider(ArrayContentProvider.getInstance()); dialog.setLabelProvider(ZColumnLabelProvider.getDefaultInstance()); dialog.setMessage(Messages.MigrateDialog_available_policies); dialog.setTitle(Messages.MigrateDialog_migration_policies); dialog.setInput(policies); if (dialog.open() == ListSelectionDialog.OK) { Object[] result = dialog.getResult(); if (result != null && result.length > 0) { MigrationPolicy policy = (MigrationPolicy) result[0]; rules = new ArrayList<MigrationRule>(Arrays.asList(policy.getRule())); fileEditor.setText(policy.getTargetCatalog()); String fsp = policy.getFileSeparatorPolicy(); fileSepearatorPolicy = MigrationPolicy_type.fileSeparatorPolicy_tOSLASH.equals(fsp) ? 1 : MigrationPolicy_type.fileSeparatorPolicy_tOBACKSLASH.equals(fsp) ? 2 : 0; fileSeparatorCombo.select(fileSepearatorPolicy); viewer.setInput(rules); updateButtons(); dirty = false; } } } return; case SAVE: File file = new File(fileEditor.getText()); String filename = file.getName(); if (filename.endsWith(BatchConstants.CATEXTENSION)) filename = filename.substring(0, filename.length() - BatchConstants.CATEXTENSION.length()); InputDialog dialog = new InputDialog(getShell(), Messages.MigrateDialog_save_migration_policy, Messages.MigrateDialog_specify_name, filename, null); if (dialog.open() == InputDialog.OK) { String name = dialog.getValue(); fileSepearatorPolicy = fileSeparatorCombo.getSelectionIndex(); String fsp = convertFileSeparatorPolicy(); MigrationPolicy policy; set = dbManager.obtainObjects(MigrationPolicy.class, "name", name, QueryField.EQUALS); //$NON-NLS-1$ List<Object> toBeDeleted = null; if (!set.isEmpty()) { if (AcousticMessageDialog.openQuestion(getShell(), Messages.MigrateDialog_save_migration_policy, Messages.MigrateDialog_policy_already_exists)) return; policy = set.get(0); toBeDeleted = new ArrayList<Object>(Arrays.asList(policy.getRule())); policy.setTargetCatalog(targetCatalog); policy.setRule(rules.toArray(new MigrationRule[rules.size()])); policy.setFileSeparatorPolicy(fsp); } else { policy = new MigrationPolicyImpl(name, fsp, fileEditor.getText()); policy.setRule(rules.toArray(new MigrationRule[rules.size()])); } List<Object> toBeStored = new ArrayList<Object>(rules.size() + 1); toBeStored.addAll(rules); toBeStored.add(policy); dbManager.safeTransaction(toBeDeleted, toBeStored); dirty = false; } return; } super.buttonPressed(buttonId); }
From source file:com.bdaum.zoom.ui.internal.dialogs.WebGalleryEditDialog.java
License:Open Source License
protected void updateParms() { StackLayout layout = (StackLayout) parmComp.getLayout(); IStructuredSelection selection = engineViewer.getStructuredSelection(); Object first = selection.getFirstElement(); if (first instanceof IConfigurationElement) { selectedEngine = (IConfigurationElement) first; Composite composite = compMap.get(selectedEngine.getAttribute("id")); //$NON-NLS-1$ layout.topControl = (composite != null) ? composite : emptyComp; } else/*from w ww .j a v a 2s . c o m*/ layout.topControl = emptyComp; parmComp.layout(); updateLabels(); }
From source file:com.bdaum.zoom.ui.internal.NavigationHistory.java
License:Open Source License
public void fireSelection(final IWorkbenchPart part, final ISelection sel) { boolean assetsChanged = false; boolean collectionChanged = false; boolean selectionChanged = false; if (sel instanceof AssetSelection) { lastSelection = sel;// w ww. j a va 2s. c o m lastPart = part; AssetSelection assetSelection = (AssetSelection) sel; assetsChanged = !assetSelection.equals(selectedAssets); if (assetsChanged) selectedAssets = assetSelection; } else if (sel instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) sel; Object first = ss.getFirstElement(); if (first instanceof SmartCollection) { lastSelection = sel; lastPart = part; if (first != selectedCollection) { selectedCollection = (SmartCollectionImpl) first; assetsChanged = selectedAssets != AssetSelection.EMPTY; selectedAssets = AssetSelection.EMPTY; collectionChanged = true; } } else { selectedItem = first; if (!ss.equals(otherSelection)) { otherSelection = ss; selectionChanged = true; } } } for (EducatedSelectionListener l : selectionListeners) { try { if (collectionChanged) l.collectionChanged(part, (IStructuredSelection) sel); if (selectionChanged) l.selectionChanged(part, sel); if (assetsChanged) l.assetsChanged(part, selectedAssets); } catch (Exception e) { UiActivator.getDefault().logError(Messages.NavigationHistory_internal_error, e); } } }
From source file:com.bdaum.zoom.ui.internal.NavigationHistory.java
License:Open Source License
public boolean updateHistory(IWorkbenchPart part, ISelection selection) { if (restoring) return false; if (selection instanceof AssetSelection) { if (!selection.isEmpty() && !previousStack.isEmpty()) { AssetSelection assetSelection = (AssetSelection) selection; HistoryItem item = previousStack.peek(); if (assetSelection.isPicked()) item.setSelectedAssets(assetSelection.getAssets()); else/*from w w w. j a v a 2s . c o m*/ item.setSelectedAssets(null); if (part instanceof AbstractGalleryView) { item.setActivePart(((BasicView) part).getViewSite().getId()); item.setSecondaryId(((BasicView) part).getViewSite().getSecondaryId()); } } return true; } if (selection instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) selection; if (sel.size() == 1 && sel.getFirstElement() instanceof IdentifiableObject) { String perspectiveId = part == null ? null : part.getSite().getPage().getPerspective().getId(); IdentifiableObject obj = (IdentifiableObject) sel.getFirstElement(); IDbManager dbManager = Core.getCore().getDbManager(); Object o = null; Date now = new Date(); if (obj instanceof SmartCollectionImpl) { ((SmartCollectionImpl) obj).setLastAccessDate(now); ((SmartCollectionImpl) obj).setPerspective(perspectiveId); o = obj.getStringId(); } else if (obj instanceof SlideShowImpl) { ((SlideShowImpl) obj).setLastAccessDate(now); ((SlideShowImpl) obj).setPerspective(perspectiveId); o = obj.getStringId(); } else if (obj instanceof ExhibitionImpl) { ((ExhibitionImpl) obj).setLastAccessDate(now); ((ExhibitionImpl) obj).setPerspective(perspectiveId); o = obj.getStringId(); } else if (obj instanceof WebGalleryImpl) { ((WebGalleryImpl) obj).setLastAccessDate(now); ((WebGalleryImpl) obj).setPerspective(perspectiveId); o = obj.getStringId(); } if (o != null) { boolean readOnly = dbManager.isReadOnly(); dbManager.setReadOnly(false); if (obj instanceof SmartCollectionImpl && ((SmartCollectionImpl) obj).getAdhoc()) dbManager.safeTransaction(null, Utilities.storeCollection((SmartCollection) obj, false, null)); else dbManager.storeAndCommit(obj); dbManager.setReadOnly(readOnly); fireQueryHistoryChanged(obj); } else o = (dbManager.exists(IdentifiableObject.class, obj.getStringId())) ? obj.getStringId() : obj; IAssetFilter[] oldfilters = previousStack.isEmpty() ? null : previousStack.peek().getFilters(); SortCriterion oldSort = previousStack.isEmpty() ? null : previousStack.peek().getSort(); return push(new HistoryItem(o, obj instanceof SmartCollection ? ((SmartCollection) obj).getGeneration() : 0, perspectiveId, oldfilters, oldSort)); } } return false; }
From source file:com.bdaum.zoom.ui.internal.preferences.AppearancePreferencePage.java
License:Open Source License
@Override protected void doPerformOk() { IPreferenceStore preferenceStore = getPreferenceStore(); int showLabel = labelConfigGroup.getSelection(); if (showLabel >= 0) { preferenceStore.setValue(PreferenceConstants.SHOWLABEL, showLabel); if (showLabel == Constants.CUSTOM_LABEL) preferenceStore.setValue(PreferenceConstants.THUMBNAILTEMPLATE, labelConfigGroup.getTemplate()); }/*from www. j a v a2 s . c o m*/ IStructuredSelection selection = colorViewer.getStructuredSelection(); if (!selection.isEmpty()) preferenceStore.setValue(PreferenceConstants.BACKGROUNDCOLOR, (String) selection.getFirstElement()); selection = distViewer.getStructuredSelection(); if (!selection.isEmpty()) preferenceStore.setValue(PreferenceConstants.DISTANCEUNIT, (String) selection.getFirstElement()); selection = dimViewer.getStructuredSelection(); if (!selection.isEmpty()) preferenceStore.setValue(PreferenceConstants.DIMUNIT, (String) selection.getFirstElement()); preferenceStore.setValue(PreferenceConstants.SHOWLOCATION, locationButton.getSelection()); preferenceStore.setValue(PreferenceConstants.MAXREGIONS, regionField.getSelection()); preferenceStore.setValue(PreferenceConstants.SHOWDONEMARK, doneButton.getSelection()); int sel = showRatingGroup.getSelection(); if (sel >= 0) preferenceStore.setValue(PreferenceConstants.SHOWRATING, ratingOptions[sel]); preferenceStore.setValue(PreferenceConstants.SHOWROTATEBUTTONS, rotateButton.getSelection()); preferenceStore.setValue(PreferenceConstants.SHOWVOICENOTE, voiceNoteButton.getSelection()); preferenceStore.setValue(PreferenceConstants.SHOWEXPANDCOLLAPSE, expandButton.getSelection()); }
From source file:com.bdaum.zoom.ui.internal.preferences.AutoPreferencePage.java
License:Open Source License
@Override protected void doPerformOk() { IPreferenceStore preferenceStore = getPreferenceStore(); preferenceStore.setValue(PreferenceConstants.AUTORULES, ruleComponent.getResult()); preferenceStore.setValue(PreferenceConstants.AUTODERIVE, autoButton.getSelection()); preferenceStore.setValue(PreferenceConstants.APPLYXMPTODERIVATES, xmpButton.getSelection()); StringBuilder sb = new StringBuilder(); for (Map.Entry<String, CheckboxButton> entry : detectorButtons.entrySet()) if (entry.getValue().getSelection()) { if (sb.length() > 0) sb.append(' '); sb.append(entry.getKey());// w ww. ja v a2s .co m } preferenceStore.setValue(PreferenceConstants.RELATIONDETECTORS, sb.toString()); if (relviewer != null) { IStructuredSelection selection = relviewer.getStructuredSelection(); if (!selection.isEmpty()) preferenceStore.setValue(PreferenceConstants.DERIVERELATIONS, (String) selection.getFirstElement()); } ruleComponent.accelerate(); }
From source file:com.bdaum.zoom.ui.internal.preferences.ColorCodePage.java
License:Open Source License
@Override public void performOk() { IPreferenceStore preferenceStore = getPreferenceStore(); IStructuredSelection selection = colorCodeViewer.getStructuredSelection(); if (!selection.isEmpty()) preferenceStore.setValue(PreferenceConstants.SHOWCOLORCODE, (String) selection.getFirstElement()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < colorCodeGroups.length; i++) sb.append(colorCodeGroups[i].encodeCriterion()).append("\n"); //$NON-NLS-1$ preferenceStore.setValue(PreferenceConstants.AUTOCOLORCODECRIT, sb.toString()); }