blob: 6b2c243c99cf8e3c12b7b1fb99c99602eaa83c65 (
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, 2014 Wind River Systems, Inc. and others. 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:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.runtime.model;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.tcf.te.runtime.model.activator.CoreBundleActivator;
/**
* A common model node representing a message.
* <p>
* <b>Note:</b> The model node implementation is not thread-safe. Clients requiring
* a thread-safe implementation should subclass the model node.
*/
public class MessageModelNode extends ModelNode {
/**
* Property: Message severity.
*/
public static final String PROPERTY_SEVERITY = "severity"; //$NON-NLS-1$
/**
* Message severity: Pending.
*/
public static final int PENDING = 0xFF;
/**
* Message model node image id: Severity Pending.
*/
public final static String OBJECT_MESSAGE_PENDING_ID = CoreBundleActivator.getUniqueIdentifier() + ".message.pending"; //$NON-NLS-1$
/**
* Message model node image id: Severity Info.
*/
public final static String OBJECT_MESSAGE_INFO_ID = CoreBundleActivator.getUniqueIdentifier() + ".message.info"; //$NON-NLS-1$
/**
* Message model node image id: Severity Warning.
*/
public final static String OBJECT_MESSAGE_WARNING_ID = CoreBundleActivator.getUniqueIdentifier() + ".message.warning"; //$NON-NLS-1$
/**
* Message model node image id: Severity Error.
*/
public final static String OBJECT_MESSAGE_ERROR_ID = CoreBundleActivator.getUniqueIdentifier() + ".message.error"; //$NON-NLS-1$
// Flag to mark the message node locked (immutable).
private boolean locked = false;
/**
* Constructor.
*
* @param message The message to show in the tree.
* @param severity The severity for the message to show as icon.
*
* @see IStatus
*/
public MessageModelNode(String message, int severity, boolean locked) {
super();
setProperty(PROPERTY_NAME, message);
setProperty(PROPERTY_SEVERITY, severity);
this.locked = locked;
}
/* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.nodes.PropertiesContainer#setProperty(java.lang.String, java.lang.Object)
*/
@Override
public boolean setProperty(String key, Object value) {
if (locked) return false;
return super.setProperty(key, value);
}
/* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.nodes.ModelNode#getImageId()
*/
@Override
public String getImageId() {
switch (getIntProperty(PROPERTY_SEVERITY)) {
case PENDING:
return OBJECT_MESSAGE_PENDING_ID;
case IStatus.INFO:
return OBJECT_MESSAGE_INFO_ID;
case IStatus.WARNING:
return OBJECT_MESSAGE_WARNING_ID;
case IStatus.ERROR:
return OBJECT_MESSAGE_ERROR_ID;
}
return null;
}
}
|