mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +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.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Common Public License v1.0 which accompanies this distribution,
|
||||
* and is available at http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
* Contributors: QNX Software Systems - Initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.ui.dialogs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -44,19 +42,22 @@ import org.eclipse.ui.help.WorkbenchHelp;
|
|||
|
||||
public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
||||
|
||||
private static final String PREFIX = "ErrorParserBlock"; // $NON-NLS-1$ //$NON-NLS-1$
|
||||
private static final String LABEL = PREFIX + ".label"; // $NON-NLS-1$ //$NON-NLS-1$
|
||||
private static final String DESC = PREFIX + ".desc"; // $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$
|
||||
private static final String DESC = PREFIX + ".desc"; // $NON-NLS-1$
|
||||
|
||||
private static String[] EMPTY = new String[0];
|
||||
private Preferences fPrefs;
|
||||
protected HashMap mapParsers = new HashMap();
|
||||
private CheckedListDialogField fErrorParserList;
|
||||
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)
|
||||
*/
|
||||
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) {
|
||||
this();
|
||||
usingDeprecatedContructor = true;
|
||||
fPrefs = prefs;
|
||||
}
|
||||
|
||||
public AbstractErrorParserBlock() {
|
||||
super(CUIPlugin.getResourceString(LABEL));
|
||||
setDescription(CUIPlugin.getResourceString(DESC));
|
||||
fPrefs = prefs;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
|
@ -77,17 +91,20 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
|||
|
||||
public void updateValues() {
|
||||
fErrorParserList.removeAllElements();
|
||||
setValues();
|
||||
setValues();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a label provider for the error parsers
|
||||
*
|
||||
*
|
||||
* @return the content provider
|
||||
*/
|
||||
protected ILabelProvider getLabelProvider() {
|
||||
return new LabelProvider() {
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
|
||||
*/
|
||||
public String getText(Object element) {
|
||||
|
@ -101,8 +118,17 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
|||
return new FieldListenerAdapter();
|
||||
}
|
||||
|
||||
protected String[] getErrorParserIDs(Preferences prefs) {
|
||||
String parserIDs = prefs.getString(ErrorParserManager.PREF_ERROR_PARSER);
|
||||
protected String[] getErrorParserIDs(boolean defaults) {
|
||||
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];
|
||||
if (parserIDs != null && parserIDs.length() > 0) {
|
||||
StringTokenizer tok = new StringTokenizer(parserIDs, ";"); //$NON-NLS-1$
|
||||
|
@ -110,21 +136,24 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
|||
while (tok.hasMoreElements()) {
|
||||
list.add(tok.nextToken());
|
||||
}
|
||||
return (String[]) list.toArray(empty);
|
||||
return (String[])list.toArray(empty);
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be implemented, abstract method.
|
||||
*
|
||||
* @param project
|
||||
* @return String[]
|
||||
*/
|
||||
protected abstract String[] getErrorParserIDs(IProject project);
|
||||
|
||||
/**
|
||||
* To be overloaded by subclasses with another method of getting the error parsers.
|
||||
* For example, the managed builder new project wizard uses the selected Target.
|
||||
* To be overloaded by subclasses with another method of getting the error
|
||||
* parsers. For example, the managed builder new project wizard uses the
|
||||
* selected Target.
|
||||
* @deprecated - use getErrorParserIDs(boolean defaults)
|
||||
* @return String[]
|
||||
*/
|
||||
protected String[] getErrorParserIDs() {
|
||||
|
@ -133,11 +162,18 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
|||
|
||||
/**
|
||||
* To be implemented. abstract method.
|
||||
*
|
||||
* @param project
|
||||
* @param parsers
|
||||
*/
|
||||
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) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
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());
|
||||
}
|
||||
|
||||
protected void saveErrorParsers(String[] parserIDs) throws CoreException {
|
||||
saveErrorParsers(fPrefs, parserIDs);
|
||||
}
|
||||
|
||||
protected void initMapParsers() {
|
||||
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) {
|
||||
IExtension[] exts = point.getExtensions();
|
||||
for (int i = 0; i < exts.length; i++) {
|
||||
|
@ -164,28 +205,39 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
|||
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() {
|
||||
String[] parserIDs;
|
||||
IProject project = getContainer().getProject();
|
||||
if (project == null) {
|
||||
if (fPrefs != null) {
|
||||
// From a Preference.
|
||||
parserIDs = getErrorParserIDs(fPrefs);
|
||||
} else {
|
||||
parserIDs = getErrorParserIDs();
|
||||
}
|
||||
parserIDs = getErrorParserIDs(false);
|
||||
} else {
|
||||
// From the Project.
|
||||
parserIDs = getErrorParserIDs(project);
|
||||
}
|
||||
updateListControl(parserIDs);
|
||||
}
|
||||
|
||||
protected void updateListControl(String[] parserIDs) {
|
||||
List checkedList = Arrays.asList(parserIDs);
|
||||
fErrorParserList.setElements(checkedList);
|
||||
fErrorParserList.setCheckedElements(checkedList);
|
||||
fErrorParserList.getTableViewer().setSelection(new StructuredSelection(checkedList.get(0)), true);
|
||||
|
||||
Iterator items = mapParsers.keySet().iterator();
|
||||
while( items.hasNext()) {
|
||||
if (checkedList.size() > 0) {
|
||||
fErrorParserList.getTableViewer().setSelection(new StructuredSelection(checkedList.get(0)), true);
|
||||
}
|
||||
Iterator items = mapParsers.keySet().iterator();
|
||||
while (items.hasNext()) {
|
||||
String item = (String)items.next();
|
||||
boolean found = false;
|
||||
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);
|
||||
|
||||
String[] buttonLabels = new String[] {
|
||||
/* 0 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.up"), //$NON-NLS-1$
|
||||
/* 1 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.down"), //$NON-NLS-1$
|
||||
/* 2 */
|
||||
null,
|
||||
/* 3 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.selectAll"), //$NON-NLS-1$
|
||||
/* 4 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.unselectAll") //$NON-NLS-1$
|
||||
String[] buttonLabels = new String[]{
|
||||
/* 0 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.up"), //$NON-NLS-1$
|
||||
/* 1 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.down"), //$NON-NLS-1$
|
||||
/* 2 */
|
||||
null,
|
||||
/* 3 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.selectAll"), //$NON-NLS-1$
|
||||
/* 4 */
|
||||
CUIMessages.getString("AbstractErrorParserBlock.label.unselectAll") //$NON-NLS-1$
|
||||
};
|
||||
|
||||
fErrorParserList = new CheckedListDialogField(null, buttonLabels, getLabelProvider());
|
||||
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.setDownButtonIndex(1);
|
||||
fErrorParserList.setCheckAllButtonIndex(3);
|
||||
fErrorParserList.setUncheckAllButtonIndex(4);
|
||||
|
||||
LayoutUtil.doDefaultLayout(composite, new DialogField[] { fErrorParserList }, true);
|
||||
LayoutUtil.doDefaultLayout(composite, new DialogField[]{fErrorParserList}, true);
|
||||
LayoutUtil.setHorizontalGrabbing(fErrorParserList.getListControl(null));
|
||||
|
||||
initializeValues();
|
||||
|
@ -249,12 +301,12 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
|||
list.add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String[] parserIDs = (String[])list.toArray(EMPTY);
|
||||
|
||||
if (project == null) {
|
||||
// Save to preferences
|
||||
saveErrorParsers(fPrefs, parserIDs);
|
||||
saveErrorParsers(parserIDs);
|
||||
} else {
|
||||
saveErrorParsers(project, parserIDs);
|
||||
}
|
||||
|
@ -264,6 +316,6 @@ public abstract class AbstractErrorParserBlock extends AbstractCOptionPage {
|
|||
}
|
||||
|
||||
public void performDefaults() {
|
||||
initializeValues();
|
||||
setDefaults();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue