Skip to content

Package: StructuredContentProvider$1

StructuredContentProvider$1

nameinstructionbranchcomplexitylinemethod
run()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /********************************************************************************
2: * Copyright (c) 2011 Eike Stepper (Berlin, Germany) and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eike Stepper - initial API and implementation
13: ********************************************************************************/
14: package org.eclipse.emf.ecp.internal.ui.model;
15:
16: import org.eclipse.jface.viewers.IStructuredContentProvider;
17: import org.eclipse.jface.viewers.Viewer;
18: import org.eclipse.swt.widgets.Control;
19: import org.eclipse.swt.widgets.Display;
20:
21: /**
22: * @author Eike Stepper
23: * @param <INPUT> The type of input (root of the tree)
24: */
25: public abstract class StructuredContentProvider<INPUT> implements IStructuredContentProvider {
26:         private Viewer viewer;
27:
28:         private INPUT input;
29:
30:         public StructuredContentProvider() {
31:         }
32:
33:         public Viewer getViewer() {
34:                 return viewer;
35:         }
36:
37:         public INPUT getInput() {
38:                 return input;
39:         }
40:
41:         /** {@inheritDoc} */
42:         @Override
43:         public final void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
44:                 this.viewer = viewer;
45:
46:                 if (input != null) {
47:                         disconnectInput(input);
48:                 }
49:
50:                 @SuppressWarnings("unchecked")
51:                 final INPUT tmp = (INPUT) newInput;
52:                 input = tmp;
53:
54:                 if (input != null) {
55:                         connectInput(input);
56:                 }
57:         }
58:
59:         public void refreshViewer() {
60:                 final Control control = viewer.getControl();
61:                 if (!control.isDisposed()) {
62:                         final Display display = control.getDisplay();
63:                         if (display.getSyncThread() != Thread.currentThread()) {
64:                                 display.asyncExec(new Runnable() {
65:                                         @Override
66:                                         public void run() {
67:•                                                if (!control.isDisposed()) {
68:                                                         viewer.refresh();
69:                                                 }
70:                                         }
71:                                 });
72:                         } else {
73:                                 viewer.refresh();
74:                         }
75:                 }
76:         }
77:
78:         /** {@inheritDoc} */
79:         @Override
80:         public void dispose() {
81:                 if (input != null) {
82:                         disconnectInput(input);
83:                 }
84:         }
85:
86:         protected void connectInput(INPUT input) {
87:                 // Can be overridden in subclasses
88:         }
89:
90:         protected void disconnectInput(INPUT input) {
91:                 // Can be overridden in subclasses
92:         }
93: }