Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2afdda4d6ceccb85d8cabc1f2392b46327f4af56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2011 Formal Mind GmbH and University of Dusseldorf.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Michael Jastram - initial API and implementation
 ******************************************************************************/
package org.eclipse.rmf.pror.reqif10.editor.propertiesview;

import org.agilemore.agilegrid.AgileGrid;
import org.agilemore.agilegrid.SWTX;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.rmf.reqif10.Identifiable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;

/**
 * 
 * The agile grid viewer for the properties view.
 * 
 * @author Lukas Ladenberger
 * 
 */
public class ProrPropertyViewer extends Viewer {

	private final AgileGrid agileGrid;
	
	private Identifiable currentSelectedSpecElement;
	
	private final ProrPropertyContentProvider contentProvider;

	public ProrPropertyViewer(Composite parent, EditingDomain editingDomain, AdapterFactory adapterFactory) {
		// Create Agile Grid
		agileGrid = new AgileGrid(parent, SWTX.AUTO_SCROLL
				| SWTX.FILL_WITH_DUMMYCOL | SWT.FLAT);
		agileGrid.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
		this.contentProvider = new ProrPropertyContentProvider(editingDomain);
		agileGrid.setContentProvider(this.contentProvider);
		agileGrid.setCellRendererProvider(new ProrPropertyCellRendererProvider(
				agileGrid, adapterFactory, editingDomain));
		agileGrid.setLayoutAdvisor(new ProrPropertyLayoutAdvisor(agileGrid));
		agileGrid.setCellEditorProvider(new ProrPropertyCellEditorProvider(
				agileGrid, adapterFactory, editingDomain));
		agileGrid.setRowResizeCursor(new Cursor(agileGrid.getDisplay(),
				SWT.CURSOR_ARROW));
	}
	
	@Override
	public Control getControl() {
		return agileGrid;
	}

	@Override
	public Object getInput() {
		return currentSelectedSpecElement;
	}

	@Override
	public ISelection getSelection() {
		return null;
	}

	@Override
	public void refresh() {
		this.contentProvider.setContent(this.currentSelectedSpecElement);
		agileGrid.redraw();
	}

	/**
	 * If a new selection was detected, set the corresponding input to the
	 * {@link ProrPropertyContentProvider}.
	 */
	@Override
	public void setInput(Object specElement) {
		if (specElement instanceof Identifiable) {
			this.currentSelectedSpecElement = (Identifiable) specElement;
		} else {
			this.currentSelectedSpecElement = null;
		}
		refresh();
	}
	
    @Override
    public void setSelection(ISelection selection, boolean reveal) {
        //Do nothing by default
    }

}

Back to the top