Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 908dda89f746e01781c657016aef3702cb0b959a (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*******************************************************************************
 * Copyright (c) 2007, 2013 Intel Corporation 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:
 *     Intel Corporation - initial API and implementation
 *     IBM Corporation
 *     Marc-Andre Laperle (Ericsson) - Adjust the columns width
 *******************************************************************************/
package org.eclipse.cdt.ui.newui;

import java.util.Collections;

import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableColumn;

import org.eclipse.cdt.core.model.util.CDTListComparator;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;

import org.eclipse.cdt.internal.ui.newui.Messages;

/**
 * @noextend This class is not intended to be subclassed by clients.
 */
public class SymbolTab extends AbstractLangsListTab {
	private TableColumn symbolColumn;
	private TableColumn valueColumn;
	private ControlAdapter listener;

	@Override
	public void additionalTableSet() {
		symbolColumn = new TableColumn(table, SWT.LEFT);
		symbolColumn.setText(Messages.SymbolTab_0);
		symbolColumn.setToolTipText(Messages.SymbolTab_0);
		valueColumn = new TableColumn(table, SWT.LEFT);
		valueColumn.setText(Messages.SymbolTab_1);
		valueColumn.setToolTipText(Messages.SymbolTab_1);
		table.getAccessible().addAccessibleListener(new AccessibleAdapter() {
			@Override
			public void getName(AccessibleEvent e) {
				e.result = Messages.SymbolTab_0;
			}
		});
	}

	@Override
	public ICLanguageSettingEntry doAdd() {
		SymbolDialog dlg = new SymbolDialog(
				usercomp.getShell(), true,
				Messages.SymbolTab_2, EMPTY_STR, EMPTY_STR, getResDesc());
		if (dlg.open() && dlg.text1.trim().length() > 0 ) {
			toAllCfgs = dlg.check1;
			toAllLang = dlg.check3;
			return CDataUtil.createCMacroEntry(dlg.text1, dlg.text2, 0);
		}
		return null;
	}

	@Override
	public ICLanguageSettingEntry doEdit(ICLanguageSettingEntry ent) {
		SymbolDialog dlg = new SymbolDialog(
				usercomp.getShell(), false,
				Messages.SymbolTab_3, ent.getName(),
				ent.getValue(), getResDesc());
		if (dlg.open())
			return CDataUtil.createCMacroEntry(dlg.text1, dlg.text2, 0);
		return null;
	}

	@Override
	public int getKind() {
		return ICSettingEntry.MACRO;
	}

	// Specific version of "update()" for Symbols tab only
	@Override
	public void update() {
		if (lang != null) {
			int x = table.getSelectionIndex();
			if (x == -1)
				x = 0;
			shownEntries = getIncs();
			Collections.sort(shownEntries, CDTListComparator.getInstance());
			tv.setInput(shownEntries.toArray(new Object[shownEntries.size()]));
			if (table.getItemCount() > x)
				table.setSelection(x);
			else if (table.getItemCount() > 0)
				table.setSelection(0);
		}
		updateStringListModeControl();
		updateStatusLine();
		updateButtons();
	}

	private void adjustColumnsWidth() {
		// Do the adjustment only once
		table.removeControlListener(listener);

		symbolColumn.pack();
		valueColumn.pack();

		int symbolColumnWidth = symbolColumn.getWidth();
		int valueColumnWidth = valueColumn.getWidth();
		int tableWidth = table.getClientArea().width;
		int excessWidth = tableWidth - symbolColumnWidth - valueColumnWidth;
		if (excessWidth > 0) {
			// Distribute excess width evenly
			symbolColumn.setWidth(symbolColumnWidth + excessWidth / 2);
			valueColumn.setWidth(valueColumnWidth + excessWidth / 2);
		} else if (excessWidth < 0) {
			// Content too large, split in two
			symbolColumn.setWidth(tableWidth / 2);
			valueColumn.setWidth(tableWidth / 2);
		}
	}

	@Override
	public void createControls(final Composite parent) {
		super.createControls(parent);
		showBIButton.setSelection(true);
		ImportExportWizardButtons.addWizardLaunchButtons(usercomp, page.getElement());

		listener = new ControlAdapter() {
			@Override
			public void controlResized(ControlEvent e) {
				adjustColumnsWidth();
			}
		};
		table.addControlListener(listener);
	}
}

Back to the top