1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

bug 274684: Indicators of string list modes for multi-configuration edits look like debug texts

This commit is contained in:
Andrew Gvozdev 2010-11-09 23:53:18 +00:00
parent 2f6862ce71
commit 8a800fe972
4 changed files with 221 additions and 149 deletions

View file

@ -28,11 +28,12 @@ import org.eclipse.cdt.core.model.util.CDTListComparator;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICMultiItemsHolder; import org.eclipse.cdt.core.settings.model.ICMultiItemsHolder;
import org.eclipse.cdt.core.settings.model.ICResourceDescription; import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
import org.eclipse.cdt.ui.newui.AbstractCPropertyTab; import org.eclipse.cdt.ui.newui.AbstractCPropertyTab;
import org.eclipse.cdt.ui.newui.AbstractPage; import org.eclipse.cdt.ui.newui.AbstractPage;
import org.eclipse.cdt.ui.newui.CDTPrefUtil; import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.ui.newui.PrefPage_Abstract; import org.eclipse.cdt.ui.newui.PrefPage_Abstract;
import org.eclipse.cdt.managedbuilder.internal.ui.Messages; import org.eclipse.cdt.ui.newui.StringListModeControl;
import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver; import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver;
import org.eclipse.cdt.utils.envvar.EnvVarOperationProcessor; import org.eclipse.cdt.utils.envvar.EnvVarOperationProcessor;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -60,8 +61,6 @@ import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
@ -71,7 +70,9 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableColumn;
@ -102,8 +103,8 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
private TableViewer tv; private TableViewer tv;
private Label fStatusLabel; private Label fStatusLabel;
private Label lb1, lb2; private StringListModeControl stringListModeControl;
private static final String[] fEditableTableColumnProps = new String[] { private static final String[] fEditableTableColumnProps = new String[] {
"editable name", //$NON-NLS-1$ "editable name", //$NON-NLS-1$
"editable type", //$NON-NLS-1$ "editable type", //$NON-NLS-1$
@ -370,32 +371,18 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
} }
}); });
lb1 = new Label(usercomp, SWT.BORDER | SWT.CENTER); stringListModeControl = new StringListModeControl(page, usercomp, 1);
lb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); stringListModeControl.addListener(SWT.Selection, new Listener() {
lb1.setToolTipText(Messages.EnvironmentTab_15); public void handleEvent(Event event) {
lb1.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
CDTPrefUtil.spinDMode();
updateData(); updateData();
}}); }
});
fStatusLabel = new Label(usercomp, SWT.LEFT); fStatusLabel = new Label(usercomp, SWT.LEFT);
fStatusLabel.setFont(usercomp.getFont()); fStatusLabel.setFont(usercomp.getFont());
fStatusLabel.setText(EMPTY_STR); fStatusLabel.setText(EMPTY_STR);
fStatusLabel.setLayoutData(new GridData(GridData.BEGINNING)); fStatusLabel.setLayoutData(new GridData(GridData.BEGINNING));
fStatusLabel.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR)); fStatusLabel.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR));
lb2 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
lb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
lb2.setToolTipText(Messages.EnvironmentTab_23);
lb2.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
CDTPrefUtil.spinWMode();
updateLbs(null, lb2);
}});
} }
private void createTableControl(){ private void createTableControl(){
@ -518,7 +505,7 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
ICdtVariable[] _vars = getVariables(); ICdtVariable[] _vars = getVariables();
if (_vars == null) return; if (_vars == null) return;
updateLbs(lb1, lb2); stringListModeControl.updateStringListModeControl();
if (cfgd == null) { if (cfgd == null) {
chkVars(); chkVars();
@ -572,9 +559,9 @@ public class CPropertyVarsTab extends AbstractCPropertyTab {
} }
/** /**
* Checks whether variable is user's * Checks whether variable is user's.
* @param v - variable to check * @param v - variable to check.
* @return * @return {@code true} if the variable is user's or {@code false} otherwise.
*/ */
private boolean isUserVar(ICdtVariable v) { private boolean isUserVar(ICdtVariable v) {
if (cfgd == null) if (cfgd == null)

View file

@ -25,7 +25,6 @@ import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlEvent;
@ -43,14 +42,12 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem; import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.cdt.core.model.ILanguageDescriptor; import org.eclipse.cdt.core.model.ILanguageDescriptor;
import org.eclipse.cdt.core.model.LanguageManager; import org.eclipse.cdt.core.model.LanguageManager;
@ -74,8 +71,6 @@ import org.eclipse.cdt.ui.CDTSharedImages;
import org.eclipse.cdt.internal.ui.newui.Messages; import org.eclipse.cdt.internal.ui.newui.Messages;
public abstract class AbstractLangsListTab extends AbstractCPropertyTab { public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
private static final String STRING_LIST_MODE_PREFERENCE_PAGE = "org.eclipse.cdt.managedbuilder.ui.preferences.PrefPage_MultiConfig"; //$NON-NLS-1$
protected Table table; protected Table table;
protected TableViewer tv; protected TableViewer tv;
protected Tree langTree; protected Tree langTree;
@ -87,7 +82,6 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
@Deprecated @Deprecated
protected Label lb1, lb2; protected Label lb1, lb2;
private Link linkStringListMode;
protected TableColumn columnToFit = null; protected TableColumn columnToFit = null;
protected ICLanguageSetting lang; protected ICLanguageSetting lang;
@ -98,6 +92,8 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
protected ICLanguageSetting [] ls; // all languages known protected ICLanguageSetting [] ls; // all languages known
private boolean fHadSomeModification; private boolean fHadSomeModification;
private StringListModeControl stringListModeControl;
private static final int BUTTON_ADD = 0; private static final int BUTTON_ADD = 0;
private static final int BUTTON_EDIT = 1; private static final int BUTTON_EDIT = 1;
private static final int BUTTON_DELETE = 2; private static final int BUTTON_DELETE = 2;
@ -225,34 +221,18 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
} }
}); });
createLinkToPreferences(usercomp, 1); stringListModeControl = new StringListModeControl(page, usercomp, 1);
stringListModeControl.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
update();
}
});
additionalTableSet(); additionalTableSet();
initButtons((getKind() == ICSettingEntry.MACRO) ? BUTTSYM : BUTTONS); initButtons((getKind() == ICSettingEntry.MACRO) ? BUTTSYM : BUTTONS);
updateData(getResDesc()); updateData(getResDesc());
} }
private void createLinkToPreferences(final Composite parent, int span) {
linkStringListMode = new Link(parent, SWT.NONE);
updateStringListModeLink(linkStringListMode);
linkStringListMode.setToolTipText(Messages.AbstractLangsListTab_MultiConfigStringListModeLinkHint);
linkStringListMode.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
// Use event.text to tell which link was used
int result = PreferencesUtil.createPreferenceDialogOn(parent.getShell(), STRING_LIST_MODE_PREFERENCE_PAGE, null, null).open();
if (result!=Window.CANCEL) {
updateStringListModeControl();
update();
}
}
});
GridData gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
gridData.horizontalSpan = span;
linkStringListMode.setLayoutData(gridData);
}
/** /**
* Used to display UI control for multiple configurations string list mode * Used to display UI control for multiple configurations string list mode
* (see Multiple Configurations Edit Preference page). * (see Multiple Configurations Edit Preference page).
@ -260,38 +240,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
* @since 5.3 * @since 5.3
*/ */
protected void updateStringListModeControl() { protected void updateStringListModeControl() {
updateStringListModeLink(linkStringListMode); stringListModeControl.updateStringListModeControl();
}
private void updateStringListModeLink(Link link) {
boolean isMultiCfg = page.isMultiCfg();
linkStringListMode.setVisible(isMultiCfg);
if (isMultiCfg) {
String modeUnknown = Messages.AbstractLangsListTab_UnknownMode;
String modeDisplay = modeUnknown;
switch (CDTPrefUtil.getInt(CDTPrefUtil.KEY_DMODE)) {
case CDTPrefUtil.DMODE_CONJUNCTION:
modeDisplay = Messages.AbstractLangsListTab_Conjunction;
break;
case CDTPrefUtil.DMODE_DISJUNCTION:
modeDisplay = Messages.AbstractLangsListTab_Disjunction;
break;
}
String modeWrite = modeUnknown;
switch (CDTPrefUtil.getInt(CDTPrefUtil.KEY_WMODE)) {
case CDTPrefUtil.WMODE_MODIFY:
modeWrite = Messages.AbstractLangsListTab_Modify;
break;
case CDTPrefUtil.WMODE_REPLACE:
modeWrite = Messages.AbstractLangsListTab_Replace;
break;
}
linkStringListMode.setText(Messages.AbstractLangsListTab_StringListMode +
" <a href=\"workspace-settings\">"+modeDisplay+"</a> + <a href=\"workspace-settings\">"+modeWrite+"</a>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
linkStringListMode.getParent().layout();
} }
/** /**

View file

@ -29,8 +29,6 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.TextProcessor; import org.eclipse.osgi.util.TextProcessor;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.SelectionListener;
@ -42,7 +40,9 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableColumn;
@ -76,8 +76,8 @@ public class EnvironmentTab extends AbstractCPropertyTab {
private TableViewer tv; private TableViewer tv;
private ArrayList<TabData> data = new ArrayList<TabData>(); private ArrayList<TabData> data = new ArrayList<TabData>();
private Button b1, b2; private Button b1, b2;
private Label lb1, lb2; private StringListModeControl stringListModeControl;
private ICConfigurationDescription cfgd = null; private ICConfigurationDescription cfgd = null;
private StorableEnvironment vars = null; private StorableEnvironment vars = null;
@ -157,7 +157,7 @@ public class EnvironmentTab extends AbstractCPropertyTab {
super.createControls(parent); super.createControls(parent);
usercomp.setLayout(new GridLayout(3, true)); usercomp.setLayout(new GridLayout(3, true));
Label l1 = new Label(usercomp, SWT.LEFT); Label l1 = new Label(usercomp, SWT.LEFT);
l1.setText(Messages.EnvironmentTab_0); l1.setText(Messages.EnvironmentTab_0);
GridData gd = new GridData(GridData.FILL_HORIZONTAL); GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 3; gd.horizontalSpan = 3;
l1.setLayoutData(gd); l1.setLayoutData(gd);
@ -168,50 +168,59 @@ public class EnvironmentTab extends AbstractCPropertyTab {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
updateButtons(); updateButtons();
} }
public void widgetDefaultSelected(SelectionEvent e) { public void widgetDefaultSelected(SelectionEvent e) {
if (buttonIsEnabled(2) && table.getSelectionIndex() != -1) if (buttonIsEnabled(2) && table.getSelectionIndex() != -1)
buttonPressed(2); buttonPressed(2);
}}); }
});
tv = new TableViewer(table); tv = new TableViewer(table);
tv.setContentProvider(new IStructuredContentProvider() { tv.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
if (inputElement != null && inputElement instanceof ArrayList<?>) { if (inputElement != null && inputElement instanceof ArrayList<?>) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<TabData> ar = (ArrayList<TabData>)inputElement; ArrayList<TabData> ar = (ArrayList<TabData>) inputElement;
return ar.toArray(new TabData[0]); return ar.toArray(new TabData[0]);
} }
return null; return null;
} }
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} public void dispose() {
}); }
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
tv.setLabelProvider(new EnvironmentLabelProvider(true)); tv.setLabelProvider(new EnvironmentLabelProvider(true));
// add headers // add headers
TableColumn tc = new TableColumn(table, SWT.LEFT); TableColumn tc = new TableColumn(table, SWT.LEFT);
tc.setText(Messages.EnvironmentTab_1); tc.setText(Messages.EnvironmentTab_1);
tc.setWidth(150); tc.setWidth(150);
tc = new TableColumn(table, SWT.LEFT); tc = new TableColumn(table, SWT.LEFT);
tc.setText(Messages.EnvironmentTab_2); tc.setText(Messages.EnvironmentTab_2);
tc.setWidth(150); tc.setWidth(150);
if (this.getResDesc() != null) { if (this.getResDesc() != null) {
tc = new TableColumn(table, SWT.LEFT); tc = new TableColumn(table, SWT.LEFT);
tc.setText(Messages.EnvironmentTab_16); tc.setText(Messages.EnvironmentTab_16);
tc.setWidth(100); tc.setWidth(100);
} }
gd = new GridData(GridData.FILL_BOTH); gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3; gd.horizontalSpan = 3;
table.setLayoutData(gd); table.setLayoutData(gd);
b1 = new Button(usercomp, SWT.RADIO); b1 = new Button(usercomp, SWT.RADIO);
b1.setText(Messages.EnvironmentTab_3); b1.setText(Messages.EnvironmentTab_3);
b1.setToolTipText(Messages.EnvironmentTab_3); b1.setToolTipText(Messages.EnvironmentTab_3);
gd = new GridData(GridData.FILL_HORIZONTAL); gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 3; if (page.isForProject())
b1.setLayoutData(gd); gd.horizontalSpan = 2;
b1.addSelectionListener(new SelectionAdapter() { else
gd.horizontalSpan = 3;
b1.setLayoutData(gd);
b1.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (cfgd != null) if (cfgd != null)
@ -219,15 +228,25 @@ public class EnvironmentTab extends AbstractCPropertyTab {
else else
vars.setAppendContributedEnvironment(true); vars.setAppendContributedEnvironment(true);
updateData(); updateData();
}}); }
});
b2 = new Button(usercomp, SWT.RADIO); if (page.isForProject()) {
b2.setText(Messages.EnvironmentTab_4); stringListModeControl = new StringListModeControl(page, usercomp, 1);
b2.setToolTipText(Messages.EnvironmentTab_4); stringListModeControl.addListener(SWT.Selection, new Listener() {
gd = new GridData(GridData.FILL_HORIZONTAL); public void handleEvent(Event event) {
gd.horizontalSpan = 3; updateData();
b2.setLayoutData(gd); }
b2.addSelectionListener(new SelectionAdapter() { });
}
b2 = new Button(usercomp, SWT.RADIO);
b2.setText(Messages.EnvironmentTab_4);
b2.setToolTipText(Messages.EnvironmentTab_4);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 3;
b2.setLayoutData(gd);
b2.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (cfgd != null) if (cfgd != null)
@ -235,33 +254,16 @@ public class EnvironmentTab extends AbstractCPropertyTab {
else else
vars.setAppendContributedEnvironment(false); vars.setAppendContributedEnvironment(false);
updateData(); updateData();
}}); }
});
if (!page.isForPrefs()) { initButtons(new String[] {
// dummy placeholder Messages.EnvironmentTab_5,
new Label(usercomp, SWT.NONE).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Messages.EnvironmentTab_6,
Messages.EnvironmentTab_7,
lb1 = new Label(usercomp, SWT.BORDER | SWT.CENTER); Messages.EnvironmentTab_8,
lb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Messages.EnvironmentTab_9
lb1.setToolTipText(Messages.EnvironmentTab_15); });
lb1.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
CDTPrefUtil.spinDMode();
updateData();
}});
lb2 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
lb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
lb2.setToolTipText(Messages.EnvironmentTab_23);
lb2.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
CDTPrefUtil.spinWMode();
updateLbs(null, lb2);
}});
}
initButtons(new String[] {Messages.EnvironmentTab_5,Messages.EnvironmentTab_6,Messages.EnvironmentTab_7,Messages.EnvironmentTab_8,Messages.EnvironmentTab_9});
} }
@Override @Override
@ -342,7 +344,7 @@ public class EnvironmentTab extends AbstractCPropertyTab {
Collections.sort(data); Collections.sort(data);
tv.setInput(data); tv.setInput(data);
updateLbs(lb1, lb2); stringListModeControl.updateStringListModeControl();
updateButtons(); updateButtons();
} }

View file

@ -0,0 +1,134 @@
/*******************************************************************************
* Copyright (c) 2010, 2010 Andrew Gvozdev (Quoin 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:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.newui;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.cdt.internal.ui.newui.Messages;
/**
* Local UI control for multiple configurations string list mode redirecting to
* Preference page "Multiple Configurations Edit".
*
* @since 5.3
*/
public class StringListModeControl {
private static final String STRING_LIST_MODE_PREFERENCE_PAGE = "org.eclipse.cdt.managedbuilder.ui.preferences.PrefPage_MultiConfig"; //$NON-NLS-1$
private ICPropertyProvider page;
private Link linkStringListMode;
private List<Listener> listeners = new ArrayList<Listener>();
/**
* Constructor.
*
* @param page - preference page.
* @param parent - parent {@code Composite} control.
* @param span - horizontal span for the control
*/
public StringListModeControl(ICPropertyProvider page, final Composite parent, int span) {
this.page = page;
linkStringListMode = new Link(parent, SWT.NONE);
updateStringListModeLink(linkStringListMode);
linkStringListMode.setToolTipText(Messages.AbstractLangsListTab_MultiConfigStringListModeLinkHint);
linkStringListMode.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
// Use event.text to tell which link was used
int result = PreferencesUtil.createPreferenceDialogOn(parent.getShell(), STRING_LIST_MODE_PREFERENCE_PAGE, null, null).open();
if (result!=Window.CANCEL) {
updateStringListModeControl();
for (Listener listener : listeners) {
listener.handleEvent(event);
}
}
}
});
GridData gridData = new GridData(SWT.RIGHT, SWT.NONE, true, false);
gridData.horizontalSpan = span;
linkStringListMode.setLayoutData(gridData);
}
/**
* Add a listener suitable for {@link org.eclipse.swt.widgets.Widget#addListener(int, Listener)}.
*
* @param eventType - the type of event to listen for, currently not used.
* @param listener - the listener which should be notified when the event occurs.
*/
public void addListener(int eventType, final Listener listener) {
listeners.add(listener);
}
/**
* Removes the listener from the collection of listeners.
*
* @param eventType the type of event to listen for, currently not used.
* @param listener the listener which should no longer be notified.
*/
protected void removeListener (int eventType, Listener listener) {
listeners.remove(listener);
}
/**
* Use to update the control when one of the string list modes gets modified .
*/
public void updateStringListModeControl() {
updateStringListModeLink(linkStringListMode);
}
/**
* Updates the message of the link presented to the user.
*
* @param link - {@code Link} object to update.
*/
private void updateStringListModeLink(Link link) {
boolean isMultiCfg = page.isMultiCfg();
linkStringListMode.setVisible(isMultiCfg);
if (isMultiCfg) {
String modeUnknown = Messages.AbstractLangsListTab_UnknownMode;
String modeDisplay = modeUnknown;
switch (CDTPrefUtil.getInt(CDTPrefUtil.KEY_DMODE)) {
case CDTPrefUtil.DMODE_CONJUNCTION:
modeDisplay = Messages.AbstractLangsListTab_Conjunction;
break;
case CDTPrefUtil.DMODE_DISJUNCTION:
modeDisplay = Messages.AbstractLangsListTab_Disjunction;
break;
}
String modeWrite = modeUnknown;
switch (CDTPrefUtil.getInt(CDTPrefUtil.KEY_WMODE)) {
case CDTPrefUtil.WMODE_MODIFY:
modeWrite = Messages.AbstractLangsListTab_Modify;
break;
case CDTPrefUtil.WMODE_REPLACE:
modeWrite = Messages.AbstractLangsListTab_Replace;
break;
}
linkStringListMode.setText(Messages.AbstractLangsListTab_StringListMode +
" <a href=\"workspace-settings\">"+modeDisplay+"</a> + <a href=\"workspace-settings\">"+modeWrite+"</a>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
linkStringListMode.getParent().layout();
}
}