/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2017 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - #7586
*******************************************************************************/
package org.simantics.diagram.ui;
@Override
public void addedToContext(ICanvasContext ctx) {
super.addedToContext(ctx);
- if (site != null && site.getSelectionProvider() != this) {
- swt.asyncExec(new Runnable() {
- @Override
- public void run() {
- if (site.getSelectionProvider() != WorkbenchSelectionProvider.this)
- site.setSelectionProvider(WorkbenchSelectionProvider.this);
- }
- });
- }
+ swt.asyncExec(() -> {
+ if (site != null && site.getSelectionProvider() != WorkbenchSelectionProvider.this)
+ site.setSelectionProvider(WorkbenchSelectionProvider.this);
+ });
}
@Override
public void removedFromContext(ICanvasContext ctx) {
- if (site != null && site.getSelectionProvider() == this) {
- swt.asyncExec(new Runnable() {
- @Override
- public void run() {
- if (site.getSelectionProvider() == WorkbenchSelectionProvider.this)
- site.setSelectionProvider(null);
- }
- });
- }
+ swt.asyncExec(() -> {
+ if (site != null && site.getSelectionProvider() == WorkbenchSelectionProvider.this)
+ site.setSelectionProvider(null);
+ });
super.removedFromContext(ctx);
}
+ public void fireSelection(Iterable<?> selection) {
+ final ISelection s = constructAdaptableSelection(selection);
+ swt.asyncExec(() -> {
+ currentSelection = s;
+ fireSelectionChanged(s);
+ schedulePostSelectionChanged(s);
+ });
+ }
+
@HintListener(Class = Selection.class, Field = "SELECTION0")
public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
Iterable<?> selection = (Iterable<?>) newValue;
- final ISelection s = constructAdaptableSelection(selection);
- swt.asyncExec(new Runnable() {
- @Override
- public void run() {
- currentSelection = s;
- fireSelectionChanged(s);
- schedulePostSelectionChanged(s);
- }
- });
+ fireSelection(selection);
}
@HintListener(Class = Selection.class, Field = "SELECTION0")
public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {
//System.out.println("selection removed: " + oldValue);
- final ISelection s = constructAdaptableSelection(Collections.emptyList());
- swt.asyncExec(new Runnable() {
- @Override
- public void run() {
- currentSelection = s;
- fireSelectionChanged(s);
- schedulePostSelectionChanged(s);
- }
- });
+ fireSelection(Collections.emptyList());
}
// Post selection changed scheduling helper.
protected void schedulePostSelectionChanged(final ISelection s) {
final int count = ++modCount;
- ThreadUtils.getNonBlockingWorkExecutor().schedule(new Runnable() {
- @Override
- public void run() {
- int newCount = modCount;
- if (count != newCount)
- return;
- if (isRemoved())
- return;
- swt.asyncExec(new Runnable() {
- @Override
- public void run() {
- if (isRemoved())
- return;
- firePostSelectionChanged(s);
- }
- });
- }
+ ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> {
+ int newCount = modCount;
+ if (count != newCount)
+ return;
+ if (isRemoved())
+ return;
+ swt.asyncExec(() -> {
+ if (!isRemoved())
+ firePostSelectionChanged(s);
+ });
}, POST_SELECTION_DELAY, TimeUnit.MILLISECONDS);
}