001/*****************************************************************************
002 * Copyright by The HDF Group.                                               *
003 * Copyright by the Board of Trustees of the University of Illinois.         *
004 * All rights reserved.                                                      *
005 *                                                                           *
006 * This file is part of the HDF Java Products distribution.                  *
007 * The full copyright notice, including terms governing use, modification,   *
008 * and redistribution, is contained in the files COPYING and Copyright.html. *
009 * COPYING can be found at the root of the source code distribution tree.    *
010 * Or, see https://support.hdfgroup.org/products/licenses.html               *
011 * If you do not have access to either file, you may request a copy from     *
012 * help@hdfgroup.org.                                                        *
013 ****************************************************************************/
014
015package hdf.view.dialog;
016
017import java.util.ArrayList;
018import java.util.Vector;
019
020import org.eclipse.swt.SWT;
021import org.eclipse.swt.layout.FillLayout;
022import org.eclipse.swt.layout.GridData;
023import org.eclipse.swt.layout.GridLayout;
024import org.eclipse.swt.widgets.Combo;
025import org.eclipse.swt.widgets.Composite;
026import org.eclipse.swt.widgets.Control;
027
028import hdf.view.ViewProperties;
029
030
031/**
032 * UserOptionsViewModulesPage.java - Configuration page for user-implementable
033 * modules.
034 */
035public class UserOptionsViewModulesPage extends UserOptionsDefaultPage {
036    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(UserOptionsViewModulesPage.class);
037
038    private Combo                 choiceTreeView, choiceMetaDataView, choiceTableView, choiceImageView, choicePaletteView;
039
040    /** A list of Tree view implementations. */
041    private static ArrayList<String> treeViews;
042
043    /** A list of Image view implementations. */
044    private static ArrayList<String> imageViews;
045
046    /** A list of Table view implementations. */
047    private static ArrayList<String> tableViews;
048
049    /** A list of metadata view implementations. */
050    private static ArrayList<String> metaDataViews;
051
052    /** A list of palette view implementations. */
053    private static ArrayList<String> paletteViews;
054
055    public UserOptionsViewModulesPage() {
056        super("View Modules Settings");
057    }
058
059    /**
060     * Performs special processing when this page's Defaults button has been pressed.
061     */
062    @Override
063    public void performDefaults() {
064        super.performDefaults();
065    }
066
067    /**
068     * Notifies that the OK button of this page's container has been pressed.
069     *
070     * @return <code>false</code> to abort the container's OK processing and <code>true</code> to allow
071     *         the OK to happen
072     */
073    @SuppressWarnings({ "unchecked", "rawtypes" })
074    @Override
075    public boolean performOk() {
076        getPreferenceStore();
077
078        ArrayList[] moduleList = { treeViews, metaDataViews, tableViews, imageViews, paletteViews };
079        Combo[] choiceList = { choiceTreeView, choiceMetaDataView, choiceTableView, choiceImageView, choicePaletteView };
080        for (int i = 0; i < moduleList.length; i++) {
081            Combo curModuleCombo = choiceList[i];
082            if (curModuleCombo != null) {
083                Object theModule = curModuleCombo.getItem(curModuleCombo.getSelectionIndex());
084                moduleList[i].remove(theModule);
085                moduleList[i].add(0, theModule);
086            }
087        }
088
089        return true;
090    }
091
092    /**
093     * Loads all stored values in the <code>FieldEditor</code>s.
094     */
095    @SuppressWarnings({ "unchecked", "rawtypes" })
096    protected void load() {
097        getPreferenceStore();
098
099        treeViews = (ArrayList<String>) ViewProperties.getTreeViewList();
100        metaDataViews = (ArrayList<String>) ViewProperties.getMetaDataViewList();
101        tableViews = (ArrayList<String>) ViewProperties.getTableViewList();
102        imageViews = (ArrayList<String>) ViewProperties.getImageViewList();
103        paletteViews = (ArrayList<String>) ViewProperties.getPaletteViewList();
104        // srbVector = (ArrayList<String>)ViewProperties.getSrbAccount();
105
106        choiceTreeView.setItems(treeViews.toArray(new String[0]));
107        choiceTreeView.select(0);
108        choiceMetaDataView.setItems(metaDataViews.toArray(new String[0]));
109        choiceMetaDataView.select(0);
110        choiceTableView.setItems(tableViews.toArray(new String[0]));
111        choiceTableView.select(0);
112        choiceImageView.setItems(imageViews.toArray(new String[0]));
113        choiceImageView.select(0);
114        choicePaletteView.setItems(paletteViews.toArray(new String[0]));
115        choicePaletteView.select(0);
116
117        ArrayList[] moduleList = { treeViews, metaDataViews, tableViews, imageViews, paletteViews };
118        Combo[] choiceList = { choiceTreeView, choiceMetaDataView, choiceTableView, choiceImageView, choicePaletteView };
119        for (int i = 0; i < moduleList.length; i++) {
120            Object theModule = choiceList[i].getItem(choiceList[i].getSelectionIndex());
121            moduleList[i].remove(theModule);
122            moduleList[i].add(0, theModule);
123        }
124    }
125
126    /**
127     * Creates and returns the SWT control for the customized body of this
128     * preference page under the given parent composite.
129     *
130     * @param parent the parent composite
131     * @return the new control
132     */
133    @Override
134    protected Control createContents(Composite parent) {
135        shell = parent.getShell();
136        Composite composite = new Composite(parent, SWT.NONE);
137        composite.setLayout(new GridLayout());
138
139        org.eclipse.swt.widgets.Group treeViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
140        treeViewGroup.setLayout(new FillLayout());
141        treeViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
142        treeViewGroup.setFont(curFont);
143        treeViewGroup.setText("TreeView Provider");
144
145        choiceTreeView = new Combo(treeViewGroup, SWT.SINGLE | SWT.READ_ONLY);
146        choiceTreeView.setFont(curFont);
147
148        org.eclipse.swt.widgets.Group metadataViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
149        metadataViewGroup.setLayout(new FillLayout());
150        metadataViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
151        metadataViewGroup.setFont(curFont);
152        metadataViewGroup.setText("MetaDataView Provider");
153
154        choiceMetaDataView = new Combo(metadataViewGroup, SWT.SINGLE | SWT.READ_ONLY);
155        choiceMetaDataView.setFont(curFont);
156
157        org.eclipse.swt.widgets.Group tableViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
158        tableViewGroup.setLayout(new FillLayout());
159        tableViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
160        tableViewGroup.setFont(curFont);
161        tableViewGroup.setText("TableView Provider");
162
163        choiceTableView = new Combo(tableViewGroup, SWT.SINGLE | SWT.READ_ONLY);
164        choiceTableView.setFont(curFont);
165
166        org.eclipse.swt.widgets.Group imageViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
167        imageViewGroup.setLayout(new FillLayout());
168        imageViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
169        imageViewGroup.setFont(curFont);
170        imageViewGroup.setText("ImageView Provider");
171
172        choiceImageView = new Combo(imageViewGroup, SWT.SINGLE | SWT.READ_ONLY);
173        choiceImageView.setFont(curFont);
174
175        org.eclipse.swt.widgets.Group paletteViewGroup = new org.eclipse.swt.widgets.Group(composite, SWT.NONE);
176        paletteViewGroup.setLayout(new FillLayout());
177        paletteViewGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
178        paletteViewGroup.setFont(curFont);
179        paletteViewGroup.setText("PaletteView Provider");
180
181        choicePaletteView = new Combo(paletteViewGroup, SWT.SINGLE | SWT.READ_ONLY);
182        choicePaletteView.setFont(curFont);
183
184        load();
185        return composite;
186
187    }
188}