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