| package org.eclipse.epp.installer.internal.ui.pages; |
| |
| import java.util.ArrayList; |
| import java.util.Collection; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.epp.installer.core.steps.CustomizeOption; |
| import org.eclipse.epp.installer.ui.IWizardStep; |
| import org.eclipse.epp.installer.ui.InstallPage; |
| import org.eclipse.jface.resource.ImageDescriptor; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.custom.StyledText; |
| import org.eclipse.swt.events.SelectionEvent; |
| import org.eclipse.swt.events.SelectionListener; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Tree; |
| import org.eclipse.swt.widgets.TreeItem; |
| |
| |
| /** |
| * Wizard page prompting the user for an installation location |
| */ |
| public class CustomizePage extends InstallPage |
| { |
| private StyledText label; |
| private Tree optionTree; |
| private TreeItem[] optionTreeItems; |
| private HashMap optionMap = new HashMap(); |
| private HashMap itemMap = new HashMap(); |
| private HashMap checkMap = new HashMap(); |
| |
| public CustomizePage(IWizardStep step, String pageName) { |
| super(step, pageName); |
| } |
| |
| public CustomizePage(IWizardStep step, String pageName, String title, ImageDescriptor titleImage) { |
| super(step, pageName, title, titleImage); |
| } |
| |
| /** |
| * Create contents of the wizard |
| * |
| * @param parent |
| */ |
| public void createControl(Composite parent) { |
| Composite container = new Composite(parent, SWT.NULL); |
| final GridLayout gridLayout = new GridLayout(); |
| gridLayout.marginHeight = 10; |
| gridLayout.marginWidth = 15; |
| container.setLayout(gridLayout); |
| setControl(container); |
| |
| createOptionTree(container); |
| createOptionText(container); |
| |
| updatePageComplete(); |
| } |
| |
| private void createOptionTree(Composite container) { |
| optionTree = new Tree(container, SWT.BORDER | SWT.CHECK); |
| optionTree.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false)); |
| optionTree.addSelectionListener(new SelectionListener() { |
| public void widgetSelected(SelectionEvent e) { |
| if (e.detail != SWT.CHECK) |
| return; |
| |
| TreeItem optionTreeItem = (TreeItem)e.item; |
| Boolean b = (Boolean)checkMap.get(optionTreeItem); |
| if (optionTreeItem.getChecked() != b.booleanValue()) { |
| checkMap.put(optionTreeItem, Boolean.valueOf(!b.booleanValue())); |
| updateSelection(optionTreeItem); |
| } |
| updatePageComplete(); |
| } |
| |
| public void widgetDefaultSelected(SelectionEvent e) { |
| widgetSelected(e); |
| } |
| }); |
| } |
| |
| private void createOptionText(Composite container) { |
| label = new StyledText(container, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP ); |
| label.setEditable(false); |
| label.setWordWrap(true); |
| label.setLayoutData(new GridData( GridData.FILL, GridData.FILL, true, true)); |
| } |
| |
| private void updateSelection(TreeItem optionTreeItem) { |
| if (optionTreeItem.getGrayed()) { |
| optionTreeItem.setChecked(true); |
| return; |
| } |
| // if (optionTreeItem.getChecked()) { |
| CustomizeOption option = (CustomizeOption)optionMap.get(optionTreeItem); |
| ArrayList dependencies = new ArrayList(option.getDepends()); |
| for (int i = 0; i < dependencies.size(); i++) { |
| TreeItem item = (TreeItem)itemMap.get(dependencies.get(i)); |
| item.setChecked(optionTreeItem.getChecked()); |
| item.setGrayed(optionTreeItem.getChecked()); |
| updateSelection(item); |
| } |
| // } |
| } |
| |
| public List getSelectedOptionList() { |
| ArrayList result = new ArrayList(); |
| for (int i = 0; i < optionTreeItems.length; i++) { |
| if (optionTreeItems[i].getChecked()) { |
| result.add(optionMap.get(optionTreeItems[i])); |
| } |
| } |
| return result; |
| } |
| |
| public void setOptionList(Collection optionList) { |
| optionTreeItems = new TreeItem[optionList.size()]; |
| int i = 0; |
| Iterator iter = optionList.iterator(); |
| while (iter.hasNext()) { |
| CustomizeOption option = (CustomizeOption)iter.next(); |
| |
| optionTreeItems[i] = new TreeItem(optionTree, SWT.CHECK); |
| optionTreeItems[i].setText(option.getName()); |
| optionTreeItems[i].setGrayed(option.getRequired()); |
| |
| optionMap.put(optionTreeItems[i], option); |
| itemMap.put(option, optionTreeItems[i]); |
| checkMap.put(optionTreeItems[i], new Boolean(false)); |
| |
| i++; |
| } |
| } |
| |
| public void setLabelText(String labelText) { |
| label.setText(labelText); |
| } |
| |
| public void setVisible(boolean visible) { |
| super.setVisible(visible); |
| if (visible) |
| setDefaultFocus(); |
| } |
| |
| /** |
| * Focus on default element |
| */ |
| public void setDefaultFocus() { |
| optionTree.setFocus(); |
| } |
| } |