blob: 45fe10f88696478569f8ef8f1e97d957c8cbdaa3 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 IBM Corporation and others.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.authoring.ui.wizards;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.epf.authoring.ui.AuthoringUIPlugin;
import org.eclipse.epf.authoring.ui.AuthoringUIResources;
import org.eclipse.epf.authoring.ui.AuthoringUIText;
import org.eclipse.epf.library.LibraryManagerFactory;
import org.eclipse.epf.library.ui.preferences.LibraryUIPreferences;
import org.eclipse.epf.ui.wizards.BaseWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* A wizard page that prompts the user to enter the name, brief description and
* type for a new method library.
*
* @author Kelvin Low
* @since 1.0
*/
public class NewLibraryMainPage extends BaseWizardPage {
/**
* The wizard page name.
*/
public static final String PAGE_NAME = NewLibraryMainPage.class.getName();
private Shell shell;
private Combo libraryPathCombo;
private Button browseButton;
private Text briefDescText;
private String libraryType;
/**
* Creates a new instance.
*/
public NewLibraryMainPage() {
super(PAGE_NAME);
setTitle(AuthoringUIResources.newLibraryWizardMainPage_title);
setDescription(AuthoringUIResources.newLibraryWizardMainPage_description);
setImageDescriptor(AuthoringUIPlugin.getDefault().getImageDescriptor(
"full/wizban/New.gif")); //$NON-NLS-1$
}
/**
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
shell = parent.getShell();
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(3, false));
createLabel(composite, AuthoringUIResources.libraryPathLabel_text);
libraryPathCombo = createCombobox(composite);
browseButton = createButton(composite,
AuthoringUIText.BROWSE_BUTTON_TEXT);
Label briefDescLabel = createLabel(composite,
AuthoringUIText.DESCRIPTION_TEXT);
briefDescLabel.setLayoutData(new GridData(
GridData.VERTICAL_ALIGN_BEGINNING));
briefDescText = createEditableText(composite, "", 480, 70, 1); //$NON-NLS-1$
Map types = LibraryManagerFactory.getInstance().getLibraryTypes();
for (Iterator it = types.keySet().iterator(); it.hasNext();) {
libraryType = (String) it.next();
break;
}
initControls();
addListeners();
setControl(composite);
}
/**
* Initializes the wizard page controls with data.
*/
protected void initControls() {
String[] newLibraryPaths = LibraryUIPreferences.getNewLibraryPaths();
libraryPathCombo.setItems(newLibraryPaths);
if (newLibraryPaths.length > 0) {
libraryPathCombo.setText(newLibraryPaths[0]);
}
}
/**
* Adds event listeners to the wizard page controls.
*/
protected void addListeners() {
libraryPathCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
setPageComplete(isPageComplete());
getWizard().getContainer().updateButtons();
}
});
libraryPathCombo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setPageComplete(isPageComplete());
getWizard().getContainer().updateButtons();
}
});
browseButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NONE);
dialog.setFilterPath(getLibraryPath());
String selectedDir = dialog.open();
if (selectedDir != null) {
libraryPathCombo.add(selectedDir, 0);
libraryPathCombo.setText(selectedDir);
}
}
});
}
/**
* @see org.eclipse.jface.wizard.WizardPage#isCompleted()
*/
public boolean isPageComplete() {
return getLibraryName().length() > 0;
}
/**
* Gets the library name.
*/
public String getLibraryName() {
String libPath = getLibraryPath();
String libName = new File(libPath).getName();
if (!libPath.equals(libName)) {
return libName;
} else {
return ""; //$NON-NLS-1$
}
}
/**
* Gets the user specified library path.
*/
public String getLibraryPath() {
return libraryPathCombo.getText().trim();
}
/**
* Gets the user specified method library description.
*/
public String getLibraryDescription() {
return briefDescText.getText().trim();
}
/**
* Gets the user specified method library type.
*/
public String getLibraryType() {
return libraryType;
}
}