mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 373029 - Fixes to inconsistencies in Codan preference page.
This commit is contained in:
parent
fb808b7db2
commit
92bd2aa4cc
1 changed files with 51 additions and 75 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009, 2011 Alena Laskavaia
|
* Copyright (c) 2009, 2012 Alena Laskavaia and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,12 +7,10 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
|
* Alex Ruiz (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.ui.preferences;
|
package org.eclipse.cdt.codan.internal.ui.preferences;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||||
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
|
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
|
||||||
|
@ -23,6 +21,7 @@ import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||||
import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
|
import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
|
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||||
import org.eclipse.jface.layout.GridDataFactory;
|
import org.eclipse.jface.layout.GridDataFactory;
|
||||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||||
|
@ -42,15 +41,18 @@ import org.eclipse.ui.IWorkbench;
|
||||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a preference page that is contributed to the
|
* This class represents a preference page that is contributed to the Preferences dialog. By
|
||||||
* Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we
|
* subclassing {@code FieldEditorPreferencePage}, we can use built-in field support in JFace to
|
||||||
* can use the field support built into JFace that allows us to create a page
|
* create a page that is both small and knows how to save, restore and apply its values.
|
||||||
* that is small and knows how to save, restore and apply itself.
|
|
||||||
* <p>
|
* <p>
|
||||||
* This page is used to modify preferences only. They are stored in the
|
* This page is used to modify preferences only. They are stored in the preference store that
|
||||||
* preference store that belongs to the main plug-in class. That way,
|
* belongs to the main plug-in class. That way, preferences can be accessed directly via the
|
||||||
* preferences can be accessed directly via the preference store.
|
* preference store.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage {
|
public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage {
|
||||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||||
|
@ -62,23 +64,20 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
|
||||||
|
|
||||||
public CodanPreferencePage() {
|
public CodanPreferencePage() {
|
||||||
super(GRID);
|
super(GRID);
|
||||||
setPreferenceStore(new ScopedPreferenceStore(new InstanceScope(), CodanCorePlugin.PLUGIN_ID));
|
setPreferenceStore(new ScopedPreferenceStore(InstanceScope.INSTANCE, CodanCorePlugin.PLUGIN_ID));
|
||||||
// setDescription("Code Analysis Preference Page");
|
|
||||||
problemSelectionListener = new ISelectionChangedListener() {
|
problemSelectionListener = new ISelectionChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void selectionChanged(SelectionChangedEvent event) {
|
public void selectionChanged(SelectionChangedEvent event) {
|
||||||
if (infoButton != null) {
|
if (infoButton != null && event.getSelection() instanceof ITreeSelection) {
|
||||||
if (event.getSelection() instanceof ITreeSelection) {
|
ITreeSelection s = (ITreeSelection) event.getSelection();
|
||||||
ITreeSelection s = (ITreeSelection) event.getSelection();
|
ArrayList<IProblem> list = new ArrayList<IProblem>();
|
||||||
ArrayList<IProblem> list = new ArrayList<IProblem>();
|
for (Iterator<?> iterator = s.iterator(); iterator.hasNext();) {
|
||||||
for (Iterator<?> iterator = s.iterator(); iterator.hasNext();) {
|
Object o = iterator.next();
|
||||||
Object o = iterator.next();
|
if (o instanceof IProblem) {
|
||||||
if (o instanceof IProblem) {
|
list.add((IProblem) o);
|
||||||
list.add((IProblem) o);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setSelectedProblems(list);
|
|
||||||
}
|
}
|
||||||
|
setSelectedProblems(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -90,9 +89,9 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the field editors. Field editors are abstractions of the common
|
* Creates the field editors. Field editors are abstractions of the common GUI blocks needed to
|
||||||
* GUI blocks needed to manipulate various types of preferences. Each field
|
* manipulate various types of preferences. Each field editor knows how to save and restore
|
||||||
* editor knows how to save and restore itself.
|
* its own value.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void createFieldEditors() {
|
public void createFieldEditors() {
|
||||||
|
@ -106,29 +105,22 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
GridData layoutData = new GridData(GridData.FILL, GridData.FILL, true, true);
|
GridData layoutData = new GridData(GridData.FILL, GridData.FILL, true, true);
|
||||||
layoutData.heightHint = 400;
|
layoutData.heightHint = 200;
|
||||||
checkedTreeEditor.getTreeViewer().getControl().setLayoutData(layoutData);
|
checkedTreeEditor.getTreeViewer().getControl().setLayoutData(layoutData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.eclipse.cdt.codan.internal.ui.preferences.FieldEditorOverlayPage#
|
|
||||||
* createContents(org.eclipse.swt.widgets.Composite)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected Control createContents(Composite parent) {
|
protected Control createContents(Composite parent) {
|
||||||
profile = isPropertyPage() ? getRegistry().getResourceProfileWorkingCopy((IResource) getElement()) : getRegistry()
|
if (isPropertyPage()) {
|
||||||
.getWorkspaceProfile();
|
profile = getRegistry().getResourceProfileWorkingCopy((IResource) getElement());
|
||||||
|
} else {
|
||||||
|
profile = getRegistry().getWorkspaceProfile();
|
||||||
|
}
|
||||||
Composite comp = (Composite) super.createContents(parent);
|
Composite comp = (Composite) super.createContents(parent);
|
||||||
createInfoControl(comp);
|
createInfoControl(comp);
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param comp
|
|
||||||
*/
|
|
||||||
private void createInfoControl(Composite comp) {
|
private void createInfoControl(Composite comp) {
|
||||||
Composite info = new Composite(comp, SWT.NONE);
|
Composite info = new Composite(comp, SWT.NONE);
|
||||||
info.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
info.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
|
@ -147,84 +139,68 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
|
||||||
restoreWidgetValues();
|
restoreWidgetValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param selection
|
|
||||||
*/
|
|
||||||
protected void setSelectedProblems(ArrayList<IProblem> list) {
|
protected void setSelectedProblems(ArrayList<IProblem> list) {
|
||||||
this.selectedProblems = list;
|
this.selectedProblems = list;
|
||||||
updateProblemInfo();
|
updateProblemInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected ICheckersRegistry getRegistry() {
|
protected ICheckersRegistry getRegistry() {
|
||||||
return CodanRuntime.getInstance().getCheckersRegistry();
|
return CodanRuntime.getInstance().getCheckersRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see org.eclipse.jface.preference.PreferencePage#performApply()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean performOk() {
|
public boolean performOk() {
|
||||||
saveWidgetValues();
|
saveWidgetValues();
|
||||||
// if (isPropertyPage())
|
|
||||||
getRegistry().updateProfile((IResource) getElement(), null);
|
getRegistry().updateProfile((IResource) getElement(), null);
|
||||||
return super.performOk();
|
return super.performOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveWidgetValues() {
|
private void saveWidgetValues() {
|
||||||
CodanUIActivator
|
String id = (!hasSelectedProblems()) ? EMPTY_STRING : selectedProblems.get(0).getId();
|
||||||
.getDefault()
|
getDialogSettings().put(getWidgetId(), id);
|
||||||
.getDialogSettings()
|
|
||||||
.put(getWidgetId(),
|
|
||||||
(selectedProblems == null || selectedProblems.size() == 0) ? EMPTY_STRING : selectedProblems.get(0).getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreWidgetValues() {
|
private void restoreWidgetValues() {
|
||||||
String id = CodanUIActivator.getDefault().getDialogSettings().get(getWidgetId());
|
String id = getDialogSettings().get(getWidgetId());
|
||||||
if (id != null && id.length() > 0 && checkedTreeEditor != null) {
|
if (id != null && id.length() > 0 && checkedTreeEditor != null) {
|
||||||
IProblem problem = profile.findProblem(id);
|
IProblem problem = profile.findProblem(id);
|
||||||
if (problem != null)
|
if (problem != null) {
|
||||||
checkedTreeEditor.getTreeViewer().setSelection(new StructuredSelection(problem), true);
|
checkedTreeEditor.getTreeViewer().setSelection(new StructuredSelection(problem), true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setSelectedProblems(null);
|
setSelectedProblems(null);
|
||||||
}
|
}
|
||||||
|
updateProblemInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDialogSettings getDialogSettings() {
|
||||||
|
return CodanUIActivator.getDefault().getDialogSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected String getWidgetId() {
|
protected String getWidgetId() {
|
||||||
return getPageId() + ".selection"; //$NON-NLS-1$
|
return getPageId() + ".selection"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProblemInfo() {
|
private void updateProblemInfo() {
|
||||||
if (selectedProblems == null) {
|
infoButton.setEnabled(hasSelectedProblems());
|
||||||
infoButton.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
infoButton.setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void init(IWorkbench workbench) {
|
public void init(IWorkbench workbench) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openCustomizeDialog() {
|
protected void openCustomizeDialog() {
|
||||||
if (selectedProblems == null || selectedProblems.size() == 0)
|
if (!hasSelectedProblems()) {
|
||||||
return;
|
return;
|
||||||
CustomizeProblemDialog dialog = new CustomizeProblemDialog(getShell(), selectedProblems.toArray(new IProblem[selectedProblems
|
}
|
||||||
.size()]), (IResource) getElement());
|
IProblem[] selected = selectedProblems.toArray(new IProblem[selectedProblems.size()]);
|
||||||
|
CustomizeProblemDialog dialog =
|
||||||
|
new CustomizeProblemDialog(getShell(), selected, (IResource) getElement());
|
||||||
dialog.open();
|
dialog.open();
|
||||||
checkedTreeEditor.getTreeViewer().refresh(true);
|
checkedTreeEditor.getTreeViewer().refresh(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasSelectedProblems() {
|
||||||
|
return selectedProblems != null && !selectedProblems.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue