mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
bug 236556: Did a little refactoring introducing BUTTON_INDEX constants instead hardcoded numbers
This commit is contained in:
parent
ed6faa6fc9
commit
0578b35b87
1 changed files with 103 additions and 93 deletions
|
@ -90,9 +90,17 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
protected ICLanguageSetting [] ls; // all languages known
|
||||
private boolean fHadSomeModification;
|
||||
|
||||
private static final int BUTTON_INDEX_ADD = 0;
|
||||
private static final int BUTTON_INDEX_EDIT = 1;
|
||||
private static final int BUTTON_INDEX_DELETE = 2;
|
||||
private static final int BUTTON_INDEX_EXPORT = 3;
|
||||
// there is a separator instead of button #4
|
||||
private static final int BUTTON_INDEX_MOVEUP = 5;
|
||||
private static final int BUTTON_INDEX_MOVEDOWN = 6;
|
||||
|
||||
protected final static String[] BUTTONS = {ADD_STR, EDIT_STR, DEL_STR,
|
||||
UIMessages.getString("AbstractLangsListTab.2"), //$NON-NLS-1$
|
||||
null, MOVEUP_STR, MOVEDOWN_STR };
|
||||
null, MOVEUP_STR, MOVEDOWN_STR };
|
||||
protected final static String[] BUTTSYM = {ADD_STR, EDIT_STR, DEL_STR,
|
||||
UIMessages.getString("AbstractLangsListTab.2")}; //$NON-NLS-1$
|
||||
|
||||
|
@ -121,14 +129,14 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
sashForm.setLayout(layout);
|
||||
|
||||
addTree(sashForm).setLayoutData(new GridData(GridData.FILL_VERTICAL));
|
||||
table = new Table(sashForm, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION);
|
||||
gd = new GridData(GridData.FILL_BOTH);
|
||||
gd.widthHint = 150;
|
||||
table.setLayoutData(gd);
|
||||
table.setHeaderVisible(isHeaderVisible());
|
||||
table.setLinesVisible(true);
|
||||
table = new Table(sashForm, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION);
|
||||
gd = new GridData(GridData.FILL_BOTH);
|
||||
gd.widthHint = 150;
|
||||
table.setLayoutData(gd);
|
||||
table.setHeaderVisible(isHeaderVisible());
|
||||
table.setLinesVisible(true);
|
||||
|
||||
sashForm.setWeights(DEFAULT_SASH_WEIGHTS);
|
||||
sashForm.setWeights(DEFAULT_SASH_WEIGHTS);
|
||||
|
||||
sashForm.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
|
@ -151,7 +159,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
}
|
||||
});
|
||||
|
||||
tv = new TableViewer(table);
|
||||
tv = new TableViewer(table);
|
||||
|
||||
tv.setContentProvider(new IStructuredContentProvider() {
|
||||
public Object[] getElements(Object inputElement) {
|
||||
|
@ -161,21 +169,22 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
||||
});
|
||||
|
||||
tv.setLabelProvider(new RichLabelProvider());
|
||||
tv.setLabelProvider(new RichLabelProvider());
|
||||
|
||||
table.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
table.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
updateButtons();
|
||||
}
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
if (buttonIsEnabled(1) && table.getSelectionIndex() != -1)
|
||||
buttonPressed(1);
|
||||
}
|
||||
});
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
table.addControlListener(new ControlListener() {
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
if (buttonIsEnabled(1) && table.getSelectionIndex() != -1)
|
||||
buttonPressed(1);
|
||||
}
|
||||
});
|
||||
|
||||
table.addControlListener(new ControlListener() {
|
||||
public void controlMoved(ControlEvent e) {
|
||||
setColumnToFit();
|
||||
}
|
||||
|
@ -183,50 +192,53 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
setColumnToFit();
|
||||
}});
|
||||
|
||||
setupLabel(usercomp, EMPTY_STR, 1, 0);
|
||||
setupLabel(usercomp, EMPTY_STR, 1, 0);
|
||||
|
||||
lb1 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
|
||||
lb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
lb1.setToolTipText(UIMessages.getString("EnvironmentTab.15")); //$NON-NLS-1$
|
||||
lb1.addMouseListener(new MouseAdapter() {
|
||||
lb1 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
|
||||
lb1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
lb1.setToolTipText(UIMessages.getString("EnvironmentTab.15")); //$NON-NLS-1$
|
||||
lb1.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
CDTPrefUtil.spinDMode();
|
||||
update();
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
showBIButton = setupCheck(usercomp, UIMessages.getString("AbstractLangsListTab.0"), 1, GridData.FILL_HORIZONTAL); //$NON-NLS-1$
|
||||
showBIButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
showBIButton = setupCheck(usercomp,
|
||||
UIMessages.getString("AbstractLangsListTab.0"), 1, GridData.FILL_HORIZONTAL); //$NON-NLS-1$
|
||||
showBIButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
update();
|
||||
}
|
||||
});
|
||||
update();
|
||||
}
|
||||
});
|
||||
|
||||
lb2 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
|
||||
lb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
lb2.setToolTipText(UIMessages.getString("EnvironmentTab.23")); //$NON-NLS-1$
|
||||
lb2.addMouseListener(new MouseAdapter() {
|
||||
lb2 = new Label(usercomp, SWT.BORDER | SWT.CENTER);
|
||||
lb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
lb2.setToolTipText(UIMessages.getString("EnvironmentTab.23")); //$NON-NLS-1$
|
||||
lb2.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
CDTPrefUtil.spinWMode();
|
||||
updateLbs(null, lb2);
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
additionalTableSet();
|
||||
initButtons((getKind() == ICSettingEntry.MACRO) ? BUTTSYM : BUTTONS);
|
||||
updateData(getResDesc());
|
||||
additionalTableSet();
|
||||
initButtons((getKind() == ICSettingEntry.MACRO) ? BUTTSYM : BUTTONS);
|
||||
updateData(getResDesc());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates state for all buttons
|
||||
* Called when table selection changes.
|
||||
*/
|
||||
@Override
|
||||
/**
|
||||
* Updates state for all buttons
|
||||
* Called when table selection changes.
|
||||
*/
|
||||
@Override
|
||||
protected void updateButtons() {
|
||||
int index = table.getSelectionIndex();
|
||||
int[] ids = table.getSelectionIndices();
|
||||
boolean canAdd = langTree.getItemCount() > 0;
|
||||
int index = table.getSelectionIndex();
|
||||
int[] ids = table.getSelectionIndices();
|
||||
boolean canAdd = langTree.getItemCount() > 0;
|
||||
boolean canExport = index != -1;
|
||||
boolean canEdit = canExport && ids.length == 1;
|
||||
boolean canDelete = canExport;
|
||||
|
@ -236,11 +248,11 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
if (ent.isReadOnly()) canEdit = false;
|
||||
if (ent.isReadOnly()) canDelete = false;
|
||||
if (exported.contains(ent))
|
||||
buttonSetText(3, UIMessages.getString("AbstractLangsListTab.4")); //$NON-NLS-1$
|
||||
buttonSetText(BUTTON_INDEX_EXPORT, UIMessages.getString("AbstractLangsListTab.4")); //$NON-NLS-1$
|
||||
else
|
||||
buttonSetText(3, UIMessages.getString("AbstractLangsListTab.2")); //$NON-NLS-1$
|
||||
buttonSetText(BUTTON_INDEX_EXPORT, UIMessages.getString("AbstractLangsListTab.2")); //$NON-NLS-1$
|
||||
} else {
|
||||
buttonSetText(3, UIMessages.getString("AbstractLangsListTab.2")); //$NON-NLS-1$
|
||||
buttonSetText(BUTTON_INDEX_EXPORT, UIMessages.getString("AbstractLangsListTab.2")); //$NON-NLS-1$
|
||||
}
|
||||
boolean canMoveUp = false;
|
||||
boolean canMoveDown = false;
|
||||
|
@ -248,18 +260,17 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
canMoveUp = canEdit && index > 0 && !ent.isBuiltIn();
|
||||
canMoveDown = canEdit && (index < table.getItemCount() - 1) && !ent.isBuiltIn();
|
||||
}
|
||||
if (canMoveDown && showBIButton.getSelection()) {
|
||||
ent = (ICLanguageSettingEntry)(table.getItem(index+1).getData());
|
||||
if (ent.isBuiltIn()) canMoveDown = false; // cannot exchange with built in
|
||||
}
|
||||
buttonSetEnabled(0, canAdd); // add
|
||||
buttonSetEnabled(1, canEdit); // edit
|
||||
buttonSetEnabled(2, canDelete); // delete
|
||||
buttonSetEnabled(3, canExport && !page.isMultiCfg()); // export
|
||||
// there is a separator instead of button #4
|
||||
buttonSetEnabled(5, canMoveUp && !page.isMultiCfg()); // up
|
||||
buttonSetEnabled(6, canMoveDown && !page.isMultiCfg()); // down
|
||||
}
|
||||
if (canMoveDown && showBIButton.getSelection()) {
|
||||
ent = (ICLanguageSettingEntry)(table.getItem(index+1).getData());
|
||||
if (ent.isBuiltIn()) canMoveDown = false; // cannot exchange with built in
|
||||
}
|
||||
buttonSetEnabled(BUTTON_INDEX_ADD, canAdd);
|
||||
buttonSetEnabled(BUTTON_INDEX_EDIT, canEdit);
|
||||
buttonSetEnabled(BUTTON_INDEX_DELETE, canDelete);
|
||||
buttonSetEnabled(BUTTON_INDEX_EXPORT, canExport && !page.isMultiCfg());
|
||||
buttonSetEnabled(BUTTON_INDEX_MOVEUP, canMoveUp && !page.isMultiCfg());
|
||||
buttonSetEnabled(BUTTON_INDEX_MOVEDOWN, canMoveDown && !page.isMultiCfg());
|
||||
}
|
||||
|
||||
private Tree addTree(Composite comp) {
|
||||
langTree = new Tree(comp, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL);
|
||||
|
@ -271,32 +282,32 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
public void widgetSelected(SelectionEvent e) {
|
||||
TreeItem[] items = langTree.getSelection();
|
||||
if (items.length > 0) {
|
||||
ICLanguageSetting ls = (ICLanguageSetting)items[0].getData();
|
||||
ICLanguageSetting ls = (ICLanguageSetting) items[0].getData();
|
||||
if (ls != null) {
|
||||
lang = ls;
|
||||
update();
|
||||
}
|
||||
}
|
||||
}});
|
||||
}
|
||||
});
|
||||
langTree.addPaintListener(new PaintListener() {
|
||||
public void paintControl(PaintEvent e) {
|
||||
int x = langTree.getBounds().width - 5;
|
||||
if (langCol.getWidth() != x)
|
||||
langCol.setWidth(x);
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
langCol = new TreeColumn(langTree, SWT.NONE);
|
||||
langCol.setText(UIMessages.getString("AbstractLangsListTab.1")); //$NON-NLS-1$
|
||||
langCol.setWidth(200);
|
||||
langCol.setResizable(false);
|
||||
langTree.getAccessible().addAccessibleListener(
|
||||
new AccessibleAdapter() {
|
||||
@Override
|
||||
public void getName(AccessibleEvent e) {
|
||||
e.result = UIMessages.getString("AbstractLangsListTab.1"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
);
|
||||
langTree.getAccessible().addAccessibleListener(new AccessibleAdapter() {
|
||||
@Override
|
||||
public void getName(AccessibleEvent e) {
|
||||
e.result = UIMessages.getString("AbstractLangsListTab.1"); //$NON-NLS-1$
|
||||
}
|
||||
});
|
||||
return langTree;
|
||||
}
|
||||
|
||||
|
@ -306,7 +317,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
public abstract int getKind();
|
||||
public abstract ICLanguageSettingEntry doAdd();
|
||||
public abstract ICLanguageSettingEntry doEdit(ICLanguageSettingEntry ent);
|
||||
public void additionalTableSet() {} // may be not overwritten
|
||||
public void additionalTableSet() {} // may be not overwritten
|
||||
|
||||
/**
|
||||
* Called when language changed or item added/edited/removed.
|
||||
|
@ -512,18 +523,18 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
int ids[] = table.getSelectionIndices();
|
||||
|
||||
switch (i) {
|
||||
case 0: // add
|
||||
case BUTTON_INDEX_ADD:
|
||||
toAllCfgs = false;
|
||||
toAllLang = false;
|
||||
performAdd(doAdd());
|
||||
break;
|
||||
case 1: // edit
|
||||
case BUTTON_INDEX_EDIT:
|
||||
performEdit(n);
|
||||
break;
|
||||
case 2: // delete
|
||||
case BUTTON_INDEX_DELETE:
|
||||
performDelete(n);
|
||||
break;
|
||||
case 3: // toggle export
|
||||
case BUTTON_INDEX_EXPORT:
|
||||
if (n == -1) return;
|
||||
for (int x=ids.length-1; x>=0; x--) {
|
||||
old = (ICLanguageSettingEntry)(table.getItem(ids[x]).getData());
|
||||
|
@ -536,13 +547,12 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
updateExport();
|
||||
update();
|
||||
break;
|
||||
// there is a separator instead of button #4
|
||||
case 5: // move up
|
||||
case 6: // move down
|
||||
case BUTTON_INDEX_MOVEUP:
|
||||
case BUTTON_INDEX_MOVEDOWN:
|
||||
old = (ICLanguageSettingEntry)(table.getItem(n).getData());
|
||||
int x = shownEntries.indexOf(old);
|
||||
if (x < 0) break;
|
||||
if (i == 6) x++; // "down" simply means "up underlying item"
|
||||
if (i == BUTTON_INDEX_MOVEDOWN) x++; // "down" simply means "up underlying item"
|
||||
old = shownEntries.get(x);
|
||||
ICLanguageSettingEntry old2 = shownEntries.get(x - 1);
|
||||
shownEntries.remove(x);
|
||||
|
@ -551,7 +561,7 @@ public abstract class AbstractLangsListTab extends AbstractCPropertyTab {
|
|||
shownEntries.add(x, old2);
|
||||
|
||||
setSettingEntries(getKind(), shownEntries, false);
|
||||
update(i == 5 ? -1 : 1);
|
||||
update(i == BUTTON_INDEX_MOVEUP ? -1 : 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue