1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +02:00

got rid of info box - replaced with tooltips

This commit is contained in:
Alena Laskavaia 2011-02-26 18:39:40 +00:00
parent 352e59b270
commit c4dc0ee219
3 changed files with 72 additions and 58 deletions

View file

@ -11,12 +11,12 @@
BuildPropertyPage_RunAsYouType=Run as you &type (selected checkers)
BuildPropertyPage_RunWithBuild=&Run with build
CheckedTreeEditor_SelectionCannotBeEmpty=Selection cannot be empty
CodanPreferencePage_Customize=Customize...
CodanPreferencePage_Customize=Customize Selected...
CodanPreferencePage_Description=Description:
CodanPreferencePage_HasPreferences=This problem has extra preferences
CodanPreferencePage_Info=Info
CodanPreferencePage_MessageLabel=Message:
CodanPreferencePage_NoInfo=Not defined
CodanPreferencePage_NoInfo=No description
CodanPreferencePage_Parameters=Parameters:
CustomizeProblemComposite_LaunchingTab=Launching
CustomizeProblemComposite_TabParameters=Preferences

View file

@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.preferences;
import java.text.MessageFormat;
import org.eclipse.cdt.codan.core.CodanCorePlugin;
import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
@ -23,7 +21,6 @@ import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@ -38,8 +35,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
@ -56,14 +51,9 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore;
*/
public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final String SINGLE_PLACEHOLDER_ONLY = "{0}"; //$NON-NLS-1$
private IProblemProfile profile;
private ISelectionChangedListener problemSelectionListener;
private IProblem selectedProblem;
private Group info;
private Label infoDesc;
private Label infoMessage;
// private Label infoParams;
private Button infoButton;
private ProblemsTreeEditor checkedTreeEditor;
@ -73,7 +63,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
// setDescription("Code Analysis Preference Page");
problemSelectionListener = new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (info != null) {
if (infoButton != null) {
if (event.getSelection() instanceof ITreeSelection) {
ITreeSelection s = (ITreeSelection) event.getSelection();
if (s.getFirstElement() instanceof IProblem)
@ -131,33 +121,13 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
* @param comp
*/
private void createInfoControl(Composite comp) {
info = new Group(comp, SWT.NONE);
Composite info = new Composite(comp, SWT.NONE);
info.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
info.setLayout(new GridLayout(2, false));
info.setText(CodanUIMessages.CodanPreferencePage_Info);
GridDataFactory gdLab = GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(false, false);
GridDataFactory gdFact = GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true);
// message
Label labelMessage = new Label(info, SWT.NONE);
labelMessage.setText(CodanUIMessages.CodanPreferencePage_MessageLabel);
labelMessage.setLayoutData(gdLab.create());
infoMessage = new Label(info, SWT.WRAP);
infoMessage.setLayoutData(gdFact.copy().create());
// description
// Label labelDesc = new Label(info, SWT.NONE);
// labelDesc.setText(CodanUIMessages.CodanPreferencePage_Description);
// labelDesc.setLayoutData(gdLab.create());
infoDesc = new Label(info, SWT.WRAP);
PixelConverter pixelConverter = new PixelConverter(comp);
infoDesc.setLayoutData(gdFact.copy().span(2, 1).hint(SWT.DEFAULT, pixelConverter.convertHeightInCharsToPixels(3)).create());
// params
// Label labelParams = new Label(info, SWT.NONE);
// labelParams.setText(CodanUIMessages.CodanPreferencePage_Parameters);
// labelParams.setLayoutData(gdLab.create());
// infoParams = new Label(info, SWT.NONE);
// infoParams.setLayoutData(gdFact.create());
GridLayout layout = new GridLayout(1, false);
layout.marginWidth=0;
info.setLayout(layout);
infoButton = new Button(info, SWT.PUSH);
infoButton.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).align(SWT.END, SWT.BEGINNING).create());
infoButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).create());
infoButton.setText(CodanUIMessages.CodanPreferencePage_Customize);
infoButton.addSelectionListener(new SelectionAdapter() {
@Override
@ -219,30 +189,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
private void updateProblemInfo() {
if (selectedProblem == null) {
infoMessage.setText(EMPTY_STRING);
infoDesc.setText(EMPTY_STRING);
// infoParams.setText(""); //$NON-NLS-1$
infoButton.setEnabled(false);
} else {
String description = selectedProblem.getDescription();
if (description == null)
description = CodanUIMessages.CodanPreferencePage_NoInfo;
String messagePattern = selectedProblem.getMessagePattern();
String message = CodanUIMessages.CodanPreferencePage_NoInfo;
if (SINGLE_PLACEHOLDER_ONLY.equals(messagePattern)) {
message = EMPTY_STRING;
} else if (messagePattern != null) {
message = MessageFormat.format(messagePattern, "X", "Y", "Z"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
infoMessage.setText(message);
infoDesc.setText(description);
// IProblemPreference pref = selectedProblem.getPreference();
// infoParams.setText(pref == null ?
// CodanUIMessages.CodanPreferencePage_NoInfo :
// CodanUIMessages.CodanPreferencePage_HasPreferences);
infoButton.setEnabled(true);
}
info.layout(true);
}
/*

View file

@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.preferences;
import java.text.MessageFormat;
import org.eclipse.cdt.codan.core.PreferenceConstants;
import org.eclipse.cdt.codan.core.model.CodanSeverity;
import org.eclipse.cdt.codan.core.model.IProblem;
@ -23,6 +25,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ICheckStateProvider;
@ -30,6 +33,7 @@ import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
@ -37,6 +41,8 @@ import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
public class ProblemsTreeEditor extends CheckedTreeEditor {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final String SINGLE_PLACEHOLDER_ONLY = "{0}"; //$NON-NLS-1$
private CodanPreferencesLoader codanPreferencesLoader = new CodanPreferencesLoader();
public ProblemsTreeEditor() {
@ -160,6 +166,8 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
// getTreeViewer().getTree().
getTreeViewer().setContentProvider(new ProblemsContentProvider());
getTreeViewer().setCheckStateProvider(new ProblemsCheckStateProvider());
//getTreeViewer().getTree().
ColumnViewerToolTipSupport.enableFor(getTreeViewer(), ToolTip.RECREATE);
// column Name
TreeViewerColumn column1 = new TreeViewerColumn(getTreeViewer(), SWT.NONE);
column1.getColumn().setWidth(300);
@ -177,6 +185,48 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
}
return null;
}
@Override
public boolean useNativeToolTip(Object object) {
return true;
}
@Override
public String getToolTipText(Object element) {
if (element instanceof IProblem) {
IProblem p = (IProblem) element;
String sampleMessage = getSampleMessage(p);
int wrapLen = sampleMessage.length();
if (wrapLen < 60)
wrapLen = 60;
if (wrapLen > 100)
wrapLen = 100;
String toolTip = ""; //$NON-NLS-1$
String description = p.getDescription();
if (description != null) {
toolTip = wrapText(description, wrapLen);
toolTip += "\n\n"; //$NON-NLS-1$
}
toolTip += "Sample Message:";
toolTip += "\n "; //$NON-NLS-1$
toolTip += wrapText(sampleMessage, wrapLen);
return toolTip;
}
return super.getToolTipText(element);
}
private String wrapText(String description, int i) {
String result = ""; //$NON-NLS-1$
while (description.length() > i) {
int k = description.lastIndexOf(' ', i);
if (k < 0)
k = i;
result += description.substring(0, k);
result += '\n';
description = description.substring(k);
}
return result + description;
}
});
// column Severity
TreeViewerColumn column2 = new TreeViewerColumn(getTreeViewer(), SWT.NONE);
@ -318,4 +368,18 @@ public class ProblemsTreeEditor extends CheckedTreeEditor {
protected String modelToString(Object model) {
return ""; //$NON-NLS-1$
}
/**
* @return
*/
public static String getSampleMessage(IProblem problem) {
String messagePattern = problem.getMessagePattern();
String message = CodanUIMessages.CodanPreferencePage_NoInfo;
if (SINGLE_PLACEHOLDER_ONLY.equals(messagePattern)) {
message = EMPTY_STRING;
} else if (messagePattern != null) {
message = MessageFormat.format(messagePattern, "X", "Y", "Z"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return message;
}
}