Skip to main content
summaryrefslogtreecommitdiffstats
blob: 750fb71d95c12af55ee9182116ccb4ad5181b121 (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
package org.eclipse.ui.examples.readmetool;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
import org.eclipse.ui.*;
import org.eclipse.jface.action.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates the contribution of a custom control to the 
 * status line for the readme editor.  The control shows the
 * dirty status of the editor.
 */
public class DirtyStateContribution extends ControlContribution
	implements IPropertyListener
{
	private Composite composite;
	private Label label;
	private IEditorPart activeEditor;
/**
 * Creates a new DirtyStateContribution.
 */
protected DirtyStateContribution() {
	super("DirtyState"); //$NON-NLS-1$
}
/* (non-Javadoc)
 * Method declared on ControlContribution
 */
protected Control createControl(Composite parent) {
	// If the composite is good just return it.
	if (composite != null && !composite.isDisposed())
		return composite;
		
	// Create composite for border.
	composite = new Composite(parent, SWT.BORDER);
	composite.setData(this);

	// Create label inside composite.	
	label = new Label(composite, SWT.NONE);
	label.setSize(80, 15);
	
	updateState();
	return composite;
}
/**
 * Called when an editor is activated.
 *
 * @see ReadmeEditorActionBarContributor#setActiveEditor(IEditorPart)
 */
public void editorChanged(IEditorPart part) {
	if (activeEditor != null) {
		activeEditor.removePropertyListener(this);
	}
	activeEditor = part;
	if (activeEditor != null) {
		activeEditor.addPropertyListener(this);
	}
	updateState();
}
/* (non-Javadoc)
 * Method declared on IPropertyListener
 */
public void propertyChanged(Object source, int propID) {
	if (source instanceof IEditorPart)
		updateState();
}
/**
 * Updates the state of the label.
 */
private void updateState() {
	if (label == null || label.isDisposed())
		return;
		
	boolean saveNeeded = false;
	if (activeEditor != null)
		saveNeeded = activeEditor.isDirty();
	if (saveNeeded)
		label.setText(MessageUtil.getString("Save_Needed")); //$NON-NLS-1$
	else
		label.setText(MessageUtil.getString("Clean")); //$NON-NLS-1$
}
}

Back to the top