mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
update error parser page to handle restore defaults correctly
This commit is contained in:
parent
73941de92e
commit
4b8468a823
1 changed files with 103 additions and 51 deletions
|
@ -1,13 +1,11 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
* Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* This program and the accompanying materials are made available under the
|
||||||
* are made available under the terms of the Common Public License v1.0
|
* terms of the Common Public License v1.0 which accompanies this distribution,
|
||||||
* which accompanies this distribution, and is available at
|
* and is available at http://www.eclipse.org/legal/cpl-v10.html
|
||||||
* http://www.eclipse.org/legal/cpl-v10.html
|
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors: QNX Software Systems - Initial API and implementation
|
||||||
* QNX Software Systems - Initial API and implementation
|
******************************************************************************/
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.ui.dialogs;
|
package org.eclipse.cdt.ui.dialogs;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -44,19 +42,22 @@ import org.eclipse.ui.help.WorkbenchHelp;
|
||||||
|
|
||||||
public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
|
|
||||||
private static final String PREFIX = "ErrorParserBlock"; // $NON-NLS-1$ //$NON-NLS-1$
|
private static final String PREFIX = "ErrorParserBlock"; // $NON-NLS-1$
|
||||||
private static final String LABEL = PREFIX + ".label"; // $NON-NLS-1$ //$NON-NLS-1$
|
private static final String LABEL = PREFIX + ".label"; // $NON-NLS-1$
|
||||||
private static final String DESC = PREFIX + ".desc"; // $NON-NLS-1$ //$NON-NLS-1$
|
private static final String DESC = PREFIX + ".desc"; // $NON-NLS-1$
|
||||||
|
|
||||||
private static String[] EMPTY = new String[0];
|
private static String[] EMPTY = new String[0];
|
||||||
private Preferences fPrefs;
|
private Preferences fPrefs;
|
||||||
protected HashMap mapParsers = new HashMap();
|
protected HashMap mapParsers = new HashMap();
|
||||||
private CheckedListDialogField fErrorParserList;
|
private CheckedListDialogField fErrorParserList;
|
||||||
protected boolean listDirty = false;
|
protected boolean listDirty = false;
|
||||||
|
private boolean usingDeprecatedContructor = false;
|
||||||
|
|
||||||
class FieldListenerAdapter implements IDialogFieldListener {
|
class FieldListenerAdapter implements IDialogFieldListener {
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField)
|
* @see org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField)
|
||||||
*/
|
*/
|
||||||
public void dialogFieldChanged(DialogField field) {
|
public void dialogFieldChanged(DialogField field) {
|
||||||
|
@ -65,10 +66,23 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated - use AbstractErrorParserBlock(), preferences setting should
|
||||||
|
* now be handled by extending classes, use
|
||||||
|
* setErrorParserIDs(boolean)/saveErrorParserIDs() to handle
|
||||||
|
* getting/setting of values.
|
||||||
|
*
|
||||||
|
* @param prefs
|
||||||
|
*/
|
||||||
public AbstractErrorParserBlock(Preferences prefs) {
|
public AbstractErrorParserBlock(Preferences prefs) {
|
||||||
|
this();
|
||||||
|
usingDeprecatedContructor = true;
|
||||||
|
fPrefs = prefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractErrorParserBlock() {
|
||||||
super(CUIPlugin.getResourceString(LABEL));
|
super(CUIPlugin.getResourceString(LABEL));
|
||||||
setDescription(CUIPlugin.getResourceString(DESC));
|
setDescription(CUIPlugin.getResourceString(DESC));
|
||||||
fPrefs = prefs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image getImage() {
|
public Image getImage() {
|
||||||
|
@ -87,7 +101,10 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
*/
|
*/
|
||||||
protected ILabelProvider getLabelProvider() {
|
protected ILabelProvider getLabelProvider() {
|
||||||
return new LabelProvider() {
|
return new LabelProvider() {
|
||||||
/* (non-Javadoc)
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
|
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public String getText(Object element) {
|
public String getText(Object element) {
|
||||||
|
@ -101,8 +118,17 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
return new FieldListenerAdapter();
|
return new FieldListenerAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] getErrorParserIDs(Preferences prefs) {
|
protected String[] getErrorParserIDs(boolean defaults) {
|
||||||
String parserIDs = prefs.getString(ErrorParserManager.PREF_ERROR_PARSER);
|
String parserIDs = null;
|
||||||
|
if (fPrefs != null) {
|
||||||
|
if (defaults == true) {
|
||||||
|
parserIDs = fPrefs.getDefaultString(ErrorParserManager.PREF_ERROR_PARSER);
|
||||||
|
} else {
|
||||||
|
parserIDs = fPrefs.getString(ErrorParserManager.PREF_ERROR_PARSER);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return getErrorParserIDs();
|
||||||
|
}
|
||||||
String[] empty = new String[0];
|
String[] empty = new String[0];
|
||||||
if (parserIDs != null && parserIDs.length() > 0) {
|
if (parserIDs != null && parserIDs.length() > 0) {
|
||||||
StringTokenizer tok = new StringTokenizer(parserIDs, ";"); //$NON-NLS-1$
|
StringTokenizer tok = new StringTokenizer(parserIDs, ";"); //$NON-NLS-1$
|
||||||
|
@ -110,21 +136,24 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
while (tok.hasMoreElements()) {
|
while (tok.hasMoreElements()) {
|
||||||
list.add(tok.nextToken());
|
list.add(tok.nextToken());
|
||||||
}
|
}
|
||||||
return (String[]) list.toArray(empty);
|
return (String[])list.toArray(empty);
|
||||||
}
|
}
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be implemented, abstract method.
|
* To be implemented, abstract method.
|
||||||
|
*
|
||||||
* @param project
|
* @param project
|
||||||
* @return String[]
|
* @return String[]
|
||||||
*/
|
*/
|
||||||
protected abstract String[] getErrorParserIDs(IProject project);
|
protected abstract String[] getErrorParserIDs(IProject project);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be overloaded by subclasses with another method of getting the error parsers.
|
* To be overloaded by subclasses with another method of getting the error
|
||||||
* For example, the managed builder new project wizard uses the selected Target.
|
* parsers. For example, the managed builder new project wizard uses the
|
||||||
|
* selected Target.
|
||||||
|
* @deprecated - use getErrorParserIDs(boolean defaults)
|
||||||
* @return String[]
|
* @return String[]
|
||||||
*/
|
*/
|
||||||
protected String[] getErrorParserIDs() {
|
protected String[] getErrorParserIDs() {
|
||||||
|
@ -133,11 +162,18 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To be implemented. abstract method.
|
* To be implemented. abstract method.
|
||||||
|
*
|
||||||
* @param project
|
* @param project
|
||||||
* @param parsers
|
* @param parsers
|
||||||
*/
|
*/
|
||||||
protected abstract void saveErrorParsers(IProject project, String[] parserIDs) throws CoreException;
|
protected abstract void saveErrorParsers(IProject project, String[] parserIDs) throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated - use saveErrorParser(String[])
|
||||||
|
* @param prefs
|
||||||
|
* @param parserIDs
|
||||||
|
*/
|
||||||
|
|
||||||
protected void saveErrorParsers(Preferences prefs, String[] parserIDs) {
|
protected void saveErrorParsers(Preferences prefs, String[] parserIDs) {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
for (int i = 0; i < parserIDs.length; i++) {
|
for (int i = 0; i < parserIDs.length; i++) {
|
||||||
|
@ -146,9 +182,14 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
prefs.setValue(ErrorParserManager.PREF_ERROR_PARSER, buf.toString());
|
prefs.setValue(ErrorParserManager.PREF_ERROR_PARSER, buf.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void saveErrorParsers(String[] parserIDs) throws CoreException {
|
||||||
|
saveErrorParsers(fPrefs, parserIDs);
|
||||||
|
}
|
||||||
|
|
||||||
protected void initMapParsers() {
|
protected void initMapParsers() {
|
||||||
mapParsers.clear();
|
mapParsers.clear();
|
||||||
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.ERROR_PARSER_SIMPLE_ID);
|
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID,
|
||||||
|
CCorePlugin.ERROR_PARSER_SIMPLE_ID);
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
IExtension[] exts = point.getExtensions();
|
IExtension[] exts = point.getExtensions();
|
||||||
for (int i = 0; i < exts.length; i++) {
|
for (int i = 0; i < exts.length; i++) {
|
||||||
|
@ -164,28 +205,39 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
setValues();
|
setValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setDefaults() {
|
||||||
|
String[] parserIDs;
|
||||||
|
IProject project = getContainer().getProject();
|
||||||
|
if (project == null) {
|
||||||
|
// From a Preference.
|
||||||
|
parserIDs = getErrorParserIDs(true);
|
||||||
|
} else {
|
||||||
|
parserIDs = getErrorParserIDs(false);
|
||||||
|
}
|
||||||
|
updateListControl(parserIDs);
|
||||||
|
}
|
||||||
|
|
||||||
protected void setValues() {
|
protected void setValues() {
|
||||||
String[] parserIDs;
|
String[] parserIDs;
|
||||||
IProject project = getContainer().getProject();
|
IProject project = getContainer().getProject();
|
||||||
if (project == null) {
|
if (project == null) {
|
||||||
if (fPrefs != null) {
|
parserIDs = getErrorParserIDs(false);
|
||||||
// From a Preference.
|
|
||||||
parserIDs = getErrorParserIDs(fPrefs);
|
|
||||||
} else {
|
|
||||||
parserIDs = getErrorParserIDs();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// From the Project.
|
// From the Project.
|
||||||
parserIDs = getErrorParserIDs(project);
|
parserIDs = getErrorParserIDs(project);
|
||||||
}
|
}
|
||||||
|
updateListControl(parserIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateListControl(String[] parserIDs) {
|
||||||
List checkedList = Arrays.asList(parserIDs);
|
List checkedList = Arrays.asList(parserIDs);
|
||||||
fErrorParserList.setElements(checkedList);
|
fErrorParserList.setElements(checkedList);
|
||||||
fErrorParserList.setCheckedElements(checkedList);
|
fErrorParserList.setCheckedElements(checkedList);
|
||||||
fErrorParserList.getTableViewer().setSelection(new StructuredSelection(checkedList.get(0)), true);
|
if (checkedList.size() > 0) {
|
||||||
|
fErrorParserList.getTableViewer().setSelection(new StructuredSelection(checkedList.get(0)), true);
|
||||||
Iterator items = mapParsers.keySet().iterator();
|
}
|
||||||
while( items.hasNext()) {
|
Iterator items = mapParsers.keySet().iterator();
|
||||||
|
while (items.hasNext()) {
|
||||||
String item = (String)items.next();
|
String item = (String)items.next();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (int i = 0; i < parserIDs.length; i++) {
|
for (int i = 0; i < parserIDs.length; i++) {
|
||||||
|
@ -206,28 +258,28 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
|
|
||||||
WorkbenchHelp.setHelp(getControl(), ICHelpContextIds.ERROR_PARSERS_PAGE);
|
WorkbenchHelp.setHelp(getControl(), ICHelpContextIds.ERROR_PARSERS_PAGE);
|
||||||
|
|
||||||
String[] buttonLabels = new String[] {
|
String[] buttonLabels = new String[]{
|
||||||
/* 0 */
|
/* 0 */
|
||||||
CUIMessages.getString("AbstractErrorParserBlock.label.up"), //$NON-NLS-1$
|
CUIMessages.getString("AbstractErrorParserBlock.label.up"), //$NON-NLS-1$
|
||||||
/* 1 */
|
/* 1 */
|
||||||
CUIMessages.getString("AbstractErrorParserBlock.label.down"), //$NON-NLS-1$
|
CUIMessages.getString("AbstractErrorParserBlock.label.down"), //$NON-NLS-1$
|
||||||
/* 2 */
|
/* 2 */
|
||||||
null,
|
null,
|
||||||
/* 3 */
|
/* 3 */
|
||||||
CUIMessages.getString("AbstractErrorParserBlock.label.selectAll"), //$NON-NLS-1$
|
CUIMessages.getString("AbstractErrorParserBlock.label.selectAll"), //$NON-NLS-1$
|
||||||
/* 4 */
|
/* 4 */
|
||||||
CUIMessages.getString("AbstractErrorParserBlock.label.unselectAll") //$NON-NLS-1$
|
CUIMessages.getString("AbstractErrorParserBlock.label.unselectAll") //$NON-NLS-1$
|
||||||
};
|
};
|
||||||
|
|
||||||
fErrorParserList = new CheckedListDialogField(null, buttonLabels, getLabelProvider());
|
fErrorParserList = new CheckedListDialogField(null, buttonLabels, getLabelProvider());
|
||||||
fErrorParserList.setDialogFieldListener(getFieldListenerAdapter());
|
fErrorParserList.setDialogFieldListener(getFieldListenerAdapter());
|
||||||
fErrorParserList.setLabelText(CUIMessages.getString("AbstractErrorParserBlock.label.errorParsers")); //$NON-NLS-1$
|
fErrorParserList.setLabelText(CUIMessages.getString("AbstractErrorParserBlock.label.errorParsers")); //$NON-NLS-1$
|
||||||
fErrorParserList.setUpButtonIndex(0);
|
fErrorParserList.setUpButtonIndex(0);
|
||||||
fErrorParserList.setDownButtonIndex(1);
|
fErrorParserList.setDownButtonIndex(1);
|
||||||
fErrorParserList.setCheckAllButtonIndex(3);
|
fErrorParserList.setCheckAllButtonIndex(3);
|
||||||
fErrorParserList.setUncheckAllButtonIndex(4);
|
fErrorParserList.setUncheckAllButtonIndex(4);
|
||||||
|
|
||||||
LayoutUtil.doDefaultLayout(composite, new DialogField[] { fErrorParserList }, true);
|
LayoutUtil.doDefaultLayout(composite, new DialogField[]{fErrorParserList}, true);
|
||||||
LayoutUtil.setHorizontalGrabbing(fErrorParserList.getListControl(null));
|
LayoutUtil.setHorizontalGrabbing(fErrorParserList.getListControl(null));
|
||||||
|
|
||||||
initializeValues();
|
initializeValues();
|
||||||
|
@ -254,7 +306,7 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
|
|
||||||
if (project == null) {
|
if (project == null) {
|
||||||
// Save to preferences
|
// Save to preferences
|
||||||
saveErrorParsers(fPrefs, parserIDs);
|
saveErrorParsers(parserIDs);
|
||||||
} else {
|
} else {
|
||||||
saveErrorParsers(project, parserIDs);
|
saveErrorParsers(project, parserIDs);
|
||||||
}
|
}
|
||||||
|
@ -264,6 +316,6 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performDefaults() {
|
public void performDefaults() {
|
||||||
initializeValues();
|
setDefaults();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue