Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 98fb01c26e3eebd4912e29a7efe0f41bc57271cf (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * Copyright (c) 2004, 2005 QNX Software Systems 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:
 * QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.propertypages; 

import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.cdt.debug.core.model.ICModule;
 
/**
 * A module's properties store. 
 */
public class ModuleProperties {

	final static public String TYPE = "type";  //$NON-NLS-1$
	final static public String CPU = "cpu";  //$NON-NLS-1$
	final static public String BASE_ADDRESS = "baseAddress";  //$NON-NLS-1$
	final static public String SIZE = "size";  //$NON-NLS-1$
	final static public String SYMBOLS_LOADED = "symbolsLoaded";  //$NON-NLS-1$
	final static public String SYMBOLS_FILE = "symbolsFile";  //$NON-NLS-1$

	public class Property {

		private String fKey;
		private Object fValue;

		/**
		 * Constructor for Property.
		 */
		public Property( String key, Object value ) {
			fKey = key;
			fValue = value;
		}

		public String getKey() {
			return fKey;
		}

		public Object getValue() {
			return fValue;
		}

		public String toString() {
			String result = ""; //$NON-NLS-1$
			if ( getKey() != null  )
				result += getKey();
			if ( getValue() != null ) {
				result += "="; //$NON-NLS-1$
				result += getValue().toString();
			}
			return result;
		}
	}

	private ArrayList fProperties;

	private boolean fIsDirty = false;

	static ModuleProperties create( ICModule module ) {
		return new ModuleProperties( module );
	}

	/** 
	 * Constructor for ModuleProperties. 
	 */
	private ModuleProperties( ICModule module ) {
		fProperties = new ArrayList( 10 );
		fProperties.add( new Property( TYPE, new Integer( module.getType() ) ) );
		fProperties.add( new Property( CPU, module.getCPU() ) );
		fProperties.add( new Property( BASE_ADDRESS, module.getBaseAddress() ) );
		fProperties.add( new Property( SIZE, new Long( module.getSize() ) ) );
		fProperties.add( new Property( SYMBOLS_LOADED, new Boolean( module.areSymbolsLoaded() ) ) );
		fProperties.add( new Property( SYMBOLS_FILE, module.getSymbolsFileName() ) );
	}

	public Property[] getProperties() {
		return (Property[])fProperties.toArray( new Property[fProperties.size()] );
	}

	public Object getProperty( String key ) {
		return find( key ).getValue();
	}

	public void setProperty( String key, Object value ) {
		Property p = find( key );
		if ( !p.getValue().equals( value ) ) {
			fProperties.set( fProperties.indexOf( p ), new Property( key, value ) );
			setDirty( true );
		}
	}

	public boolean isDirty() {
		return fIsDirty;
	}

	public void dispose() {
		fProperties.clear();
	}

	private void setDirty( boolean dirty ) {
		fIsDirty = dirty;
	}

	private Property find( String key ) {
		Iterator it = fProperties.iterator();
		while( it.hasNext() ) {
			Property p = (Property)it.next();
			if ( p.getKey().equals( key ) ) {
				return p;
			}
		}
		throw new IllegalArgumentException( key );
	}
}

Back to the top