001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.plugin.properties;
034:
035: /**
036: * @author Guillaume Bort
037: */
038: import org.eclipse.core.resources.IProject;
039:
040: import org.eclipse.jface.preference.PreferencePage;
041:
042: import org.eclipse.swt.SWT;
043: import org.eclipse.swt.events.MouseEvent;
044: import org.eclipse.swt.events.MouseListener;
045: import org.eclipse.swt.graphics.Color;
046: import org.eclipse.swt.graphics.RGB;
047: import org.eclipse.swt.layout.GridData;
048: import org.eclipse.swt.layout.GridLayout;
049: import org.eclipse.swt.widgets.Button;
050: import org.eclipse.swt.widgets.Composite;
051: import org.eclipse.swt.widgets.Control;
052: import org.eclipse.swt.widgets.Label;
053: import org.eclipse.swt.widgets.Text;
054:
055: import org.eclipse.ui.dialogs.PropertyPage;
056:
057: import org.libresource.so6.plugin.core.So6Util;
058:
059: /**
060: * DOCUMENT ME!
061: *
062: * @author $author$
063: * @version $Revision: 1.3 $
064: */
065: public class So6PropertyPage extends PropertyPage {
066: /** DOCUMENT ME! */
067: public static String PATH_PROPERTY = "SO6_PATH";
068:
069: /** DOCUMENT ME! */
070: public static String DEFAULT_PATH = ".so6/1/so6.properties";
071: private Button browse;
072: private Label exist;
073: private Text so6Path;
074:
075: /**
076: * Creates a new So6PropertyPage object.
077: */
078: public So6PropertyPage() {
079: super ();
080: }
081:
082: /**
083: * DOCUMENT ME!
084: *
085: * @return DOCUMENT ME!
086: */
087: public boolean performOk() {
088: // store the value in the owner text field
089: try {
090: So6Util.setSo6PropertiesPath((IProject) getElement(),
091: so6Path.getText());
092: checkFileExist();
093: } catch (Exception e) {
094: return false;
095: }
096:
097: return true;
098: }
099:
100: /**
101: *
102: * @see PreferencePage#createContents(Composite)
103: */
104: protected Control createContents(Composite parent) {
105: Composite composite = new Composite(parent, SWT.NONE);
106: GridLayout layout = new GridLayout();
107: composite.setLayout(layout);
108:
109: GridData data = new GridData(GridData.FILL);
110: data.grabExcessHorizontalSpace = true;
111: composite.setLayoutData(data);
112:
113: addFirstSection(composite);
114: addSeparator(composite);
115: addSecondSection(composite);
116:
117: return composite;
118: }
119:
120: /**
121: * DOCUMENT ME!
122: */
123: protected void performDefaults() {
124: // Populate the owner text field with the default value
125: so6Path.setText(DEFAULT_PATH);
126: checkFileExist();
127: }
128:
129: private void addFirstSection(Composite parent) {
130: Composite composite = createDefaultComposite(parent);
131: Label label = new Label(composite, SWT.NONE);
132: label.setText("This project is a So6 project");
133: exist = new Label(composite, SWT.NONE);
134: exist.setForeground(new Color(getShell().getDisplay(), new RGB(
135: 255, 0, 0)));
136: checkFileExist();
137: }
138:
139: private void addSecondSection(Composite parent) {
140: Composite composite = createDefaultComposite(parent);
141:
142: // Label for owner field
143: Label ownerLabel = new Label(composite, SWT.NONE);
144: ownerLabel.setText("so6.properties file path : ");
145:
146: // Owner text field
147: so6Path = new Text(composite, SWT.SINGLE | SWT.BORDER);
148:
149: GridData gd = new GridData();
150: gd.widthHint = convertWidthInCharsToPixels(45);
151: so6Path.setLayoutData(gd);
152:
153: // Populate owner text field
154: String path = So6Util
155: .getSo6PropertiesPath((IProject) getElement());
156: so6Path.setText(path);
157:
158: // Browse
159: browse = new Button(composite, SWT.NONE);
160: browse.setText("browse...");
161: browse.addMouseListener(new MouseListener() {
162: public void mouseDoubleClick(MouseEvent e) {
163: }
164:
165: public void mouseDown(MouseEvent e) {
166: }
167:
168: public void mouseUp(MouseEvent e) {
169: }
170: });
171: }
172:
173: private void addSeparator(Composite parent) {
174: Label separator = new Label(parent, SWT.SEPARATOR
175: | SWT.HORIZONTAL);
176: GridData gridData = new GridData();
177: gridData.horizontalAlignment = GridData.FILL;
178: gridData.grabExcessHorizontalSpace = true;
179: separator.setLayoutData(gridData);
180: }
181:
182: private void checkFileExist() {
183: try {
184: So6Util.checkIfSo6PropertiesExist((IProject) getElement());
185: exist
186: .setText(" ");
187: } catch (Exception e) {
188: exist
189: .setText("(The file "
190: + So6Util
191: .getSo6PropertiesPath((IProject) getElement())
192: + " does not exist)");
193: }
194: }
195:
196: private Composite createDefaultComposite(Composite parent) {
197: Composite composite = new Composite(parent, SWT.NULL);
198: GridLayout layout = new GridLayout();
199: layout.numColumns = 3;
200: composite.setLayout(layout);
201:
202: GridData data = new GridData();
203: data.verticalAlignment = GridData.FILL;
204: data.horizontalAlignment = GridData.FILL;
205: composite.setLayoutData(data);
206:
207: return composite;
208: }
209: }
|