001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal.provisional.views.markers.api;
011:
012: import org.eclipse.jface.dialogs.Dialog;
013: import org.eclipse.jface.dialogs.IDialogConstants;
014: import org.eclipse.jface.resource.JFaceResources;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.graphics.FontMetrics;
017: import org.eclipse.swt.graphics.GC;
018: import org.eclipse.swt.graphics.Point;
019: import org.eclipse.swt.layout.GridData;
020: import org.eclipse.swt.widgets.Button;
021: import org.eclipse.swt.widgets.Composite;
022: import org.eclipse.swt.widgets.Control;
023:
024: /**
025: * FilterConfigurationArea is the area that the user can configure a filter in.
026: *
027: * @since 3.4
028: *
029: */
030: public abstract class FilterConfigurationArea {
031:
032: MarkerField field;
033:
034: private FontMetrics fontMetrics;
035:
036: /**
037: * Apply the current settings to the filter.
038: *
039: * @param filter
040: */
041: public abstract void apply(MarkerFieldFilter filter);
042:
043: /**
044: * Create the contents of the configuration area in the parent.
045: *
046: * @param parent
047: */
048: public abstract void createContents(Composite parent);
049:
050: /**
051: * Return the {@link FontMetrics} for the receiver.
052: * @return {@link FontMetrics} or <code>null</code> if {@link #initializeFontMetrics(Control)}
053: * has not been called.
054: */
055: protected FontMetrics getFontMetrics() {
056: return fontMetrics;
057: }
058:
059: /**
060: * Get the title for the receiver.
061: *
062: * @return
063: */
064: public String getTitle() {
065: return field.getColumnHeaderText();
066: }
067:
068: /**
069: * Initialise {@link FontMetrics} for the receiver.
070: *
071: * @param control
072: */
073: protected void initializeFontMetrics(Control control) {
074: GC gc = new GC(control);
075: gc.setFont(JFaceResources.getDialogFont());
076: fontMetrics = gc.getFontMetrics();
077: gc.dispose();
078:
079: }
080:
081: /**
082: * Initialise the receiver using the filter.
083: *
084: * @param filter
085: */
086: public abstract void initialize(MarkerFieldFilter filter);
087:
088: /**
089: * Set the markerField for the receiver
090: *
091: * @param markerField
092: */
093: public void setField(MarkerField markerField) {
094: field = markerField;
095: }
096:
097: /**
098: * Set the standard button data for the button.
099: * @param button
100: */
101: protected void setButtonLayoutData(Button button) {
102: GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
103: int widthHint = Dialog.convertHorizontalDLUsToPixels(
104: getFontMetrics(), IDialogConstants.BUTTON_WIDTH);
105: Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT,
106: true);
107: data.widthHint = Math.max(widthHint, minSize.x);
108: button.setLayoutData(data);
109:
110: }
111:
112: /**
113: * Return the field for the receiver.
114: * @return
115: */
116: public MarkerField getField() {
117: return field;
118: }
119:
120: }
|