001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package org.terracotta.dso.dialogs;
006:
007: import org.eclipse.core.resources.IFile;
008: import org.eclipse.core.resources.IMarker;
009: import org.eclipse.core.resources.IProject;
010: import org.eclipse.core.resources.IResource;
011: import org.eclipse.core.runtime.CoreException;
012: import org.eclipse.jface.dialogs.IDialogConstants;
013: import org.eclipse.jface.dialogs.MessageDialog;
014: import org.eclipse.jface.resource.ImageDescriptor;
015: import org.eclipse.jface.resource.JFaceResources;
016: import org.eclipse.swt.SWT;
017: import org.eclipse.swt.events.SelectionAdapter;
018: import org.eclipse.swt.events.SelectionEvent;
019: import org.eclipse.swt.graphics.Image;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.layout.GridLayout;
022: import org.eclipse.swt.widgets.Button;
023: import org.eclipse.swt.widgets.Composite;
024: import org.eclipse.swt.widgets.Control;
025: import org.eclipse.swt.widgets.Shell;
026: import org.eclipse.swt.widgets.Table;
027: import org.eclipse.swt.widgets.TableColumn;
028: import org.eclipse.swt.widgets.TableItem;
029: import org.eclipse.ui.PlatformUI;
030: import org.terracotta.dso.TcPlugin;
031: import org.terracotta.dso.editors.ConfigurationEditor;
032: import org.terracotta.ui.util.SWTUtil;
033:
034: public class ConfigProblemsDialog extends MessageDialog {
035:
036: private final Shell fParentShell;
037: private final IProject fProject;
038: private Table fTable;
039: private Button fDisableConfigWarningsButton;
040:
041: private static String DISABLE_CONFIG_WARNINGS_MSG = "Always proceed even if there are config problems";
042:
043: private static String TITLE = "Terracotta";
044: private static String MSG = "The are problems with the Terracotta configuration. Continue?";
045:
046: private static Image ERROR_IMG = getSharedImage("IMG_OBJS_ERROR_PATH");
047: private static Image WARNING_IMG = getSharedImage("IMG_OBJS_WARNING_PATH");
048: private static Image INFO_IMG = getSharedImage("IMG_OBJS_INFO_PATH");
049:
050: public ConfigProblemsDialog(Shell shell, IProject project) {
051: super (shell, TITLE, null, MSG, MessageDialog.NONE,
052: new String[] { IDialogConstants.OK_LABEL,
053: IDialogConstants.CANCEL_LABEL }, 0);
054: setShellStyle(getShellStyle() | SWT.RESIZE);
055: fProject = project;
056: fParentShell = shell;
057: }
058:
059: protected void configureShell(Shell shell) {
060: super .configureShell(shell);
061: if (fParentShell != null) {
062: SWTUtil.placeDialogInCenter(fParentShell, shell);
063: }
064: }
065:
066: protected Control createDialogArea(Composite parent) {
067: parent.setLayout(new GridLayout());
068: return super .createDialogArea(parent);
069: }
070:
071: protected Control createCustomArea(Composite parent) {
072: Composite comp = new Composite(parent, SWT.NONE);
073: comp.setLayout(new GridLayout());
074: comp.setLayoutData(new GridData(GridData.FILL_BOTH));
075:
076: fTable = new Table(comp, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE
077: | SWT.FULL_SELECTION);
078: fTable.addSelectionListener(new SelectionAdapter() {
079: public void widgetSelected(SelectionEvent e) {
080: try {
081: ConfigurationEditor configEditor = TcPlugin
082: .getDefault().openConfigurationEditor(
083: fProject);
084: TableItem item = fTable.getSelection()[0];
085: configEditor.gotoMarker((IMarker) item.getData());
086: } catch (Exception ex) {
087: ex.printStackTrace();
088: }
089: }
090: });
091: fTable.setHeaderVisible(true);
092: fTable.setLinesVisible(true);
093:
094: TableColumn fieldCol = new TableColumn(fTable, SWT.NONE);
095: fieldCol.setResizable(true);
096: fieldCol.setText("Description");
097: fieldCol.pack();
098:
099: TableColumn nameCol = new TableColumn(fTable, SWT.NONE);
100: nameCol.setResizable(true);
101: nameCol.setText("Location");
102: nameCol.pack();
103:
104: SWTUtil.makeTableColumnsResizeWeightedWidth(comp, fTable,
105: new int[] { 5, 1 });
106: GridData gridData = new GridData(GridData.FILL_BOTH);
107: gridData.heightHint = SWTUtil.tableRowsToPixels(fTable, 5);
108: gridData.widthHint = SWTUtil.textColumnsToPixels(fTable, 120);
109: fTable.setLayoutData(gridData);
110:
111: IFile configFile = TcPlugin.getDefault().getConfigurationFile(
112: fProject);
113: IMarker[] markers = null;
114: try {
115: markers = configFile.findMarkers(
116: "org.eclipse.core.resources.problemmarker", true,
117: IResource.DEPTH_ZERO);
118: } catch (CoreException ce) {
119: ce.printStackTrace();
120: }
121: if (markers != null && markers.length > 0) {
122: for (IMarker marker : markers) {
123: TableItem item = new TableItem(fTable, SWT.NONE);
124: item.setData(marker);
125: item.setImage(getImage(marker));
126: item.setText(new String[] {
127: marker.getAttribute(IMarker.MESSAGE, ""),
128: "line "
129: + marker.getAttribute(
130: IMarker.LINE_NUMBER, 0) });
131: }
132: }
133:
134: fDisableConfigWarningsButton = new Button(comp, SWT.CHECK);
135: fDisableConfigWarningsButton.setLayoutData(new GridData());
136: fDisableConfigWarningsButton
137: .setText(DISABLE_CONFIG_WARNINGS_MSG);
138: fDisableConfigWarningsButton.setSelection(!TcPlugin
139: .getDefault().getWarnConfigProblemsOption(fProject));
140: fDisableConfigWarningsButton
141: .addSelectionListener(new SelectionAdapter() {
142: public void widgetSelected(SelectionEvent e) {
143: boolean disableWarn = fDisableConfigWarningsButton
144: .getSelection();
145: TcPlugin.getDefault()
146: .setWarnConfigProblemsOption(fProject,
147: !disableWarn);
148: }
149: });
150:
151: return parent;
152: }
153:
154: private static Image getImage(IMarker marker) {
155: switch (marker.getAttribute(IMarker.SEVERITY, 0)) {
156: case IMarker.SEVERITY_ERROR:
157: return ERROR_IMG;
158: case IMarker.SEVERITY_WARNING:
159: return WARNING_IMG;
160: case IMarker.SEVERITY_INFO:
161: return INFO_IMG;
162: default:
163: return null;
164: }
165: }
166:
167: private static Image getSharedImage(String symbolicName) {
168: ImageDescriptor imageDesc = PlatformUI.getWorkbench()
169: .getSharedImages().getImageDescriptor(symbolicName);
170: if (imageDesc != null) {
171: return JFaceResources.getResources()
172: .createImageWithDefault(imageDesc);
173: }
174: return null;
175: }
176: }
|