blob: c4e3f0795a6ba0ae93f20b36a7a4c6fbf84f8b24 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* 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:
<<<<<<< HEAD
* Pierre Allard - initial API and implementation
* Regent L'Archeveque
*
=======
* Pierre Allard,
* Regent L'Archeveque,
* Sebastien Gemme - initial API and implementation
*
>>>>>>> refs/heads/eclipse_pa
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.converters.ui.wizards;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.apogy.common.converters.IFileExporter;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
public class ExportFileSettingsWizardPage extends WizardPage {
private final IFileExporter iFileExporter;
private Composite container;
private TableViewer availableExtensionsViewer;
private TableViewer toExportExtensionsViewer;
private Text txtDescription;
private Button addButton;
private Button removeButton;
private final List<String> availableExtensions = new ArrayList<String>();
private final List<String> toExportExtensions = new ArrayList<String>();
private final List<String> selectedExtensions = new ArrayList<String>();
public ExportFileSettingsWizardPage(String pageName, IFileExporter iFileExporter, ExportToFileWizard wizard) {
super(pageName);
setDescription("Select the file extension to use for the export.");
this.iFileExporter = iFileExporter;
this.availableExtensions.addAll(iFileExporter.getSupportedFileExtensions());
}
@Override
public void createControl(Composite parent) {
this.container = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(3, false);
this.container.setLayout(layout);
Label lblAvailableExtensions = new Label(this.container, SWT.NONE);
lblAvailableExtensions.setText("Available Extensions");
lblAvailableExtensions.setAlignment(SWT.CENTER);
lblAvailableExtensions.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
// Filler
new Label(this.container, SWT.NONE);
Label lblToExportExtensions = new Label(this.container, SWT.NONE);
lblToExportExtensions.setText("Extension To Export");
lblToExportExtensions.setAlignment(SWT.CENTER);
lblToExportExtensions.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
// Available Extension Viewer
this.availableExtensionsViewer = new TableViewer(this.container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
Table table = this.availableExtensionsViewer.getTable();
GridData gd_table = new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 2);
gd_table.minimumWidth = 300;
gd_table.widthHint = 300;
table.setLayoutData(gd_table);
table.setLinesVisible(true);
ColumnViewerToolTipSupport.enableFor(this.availableExtensionsViewer);
this.availableExtensionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ExportFileSettingsWizardPage.this.addButton.setEnabled(true);
ExportFileSettingsWizardPage.this.removeButton.setEnabled(false);
if (event.getSelection() instanceof IStructuredSelection) {
ExportFileSettingsWizardPage.this.selectedExtensions.clear();
IStructuredSelection iStructuredSelection = (IStructuredSelection) event.getSelection();
@SuppressWarnings("unchecked")
Iterator<Object> it = iStructuredSelection.iterator();
while (it.hasNext()) {
Object item = it.next();
if (item instanceof String) {
String extension = (String) item;
ExportFileSettingsWizardPage.this.selectedExtensions.add(extension);
String description = ExportFileSettingsWizardPage.this.iFileExporter
.getDescription(extension);
if (description == null)
description = "No description available.";
ExportFileSettingsWizardPage.this.txtDescription.setText(description);
}
}
}
}
});
TableViewerColumn tableViewerColumnItem_Name = new TableViewerColumn(this.availableExtensionsViewer, SWT.NONE);
TableColumn trclmnItemName = tableViewerColumnItem_Name.getColumn();
trclmnItemName.setText("Extension");
trclmnItemName.setWidth(100);
this.availableExtensionsViewer.setContentProvider(new ArrayContentProvider());
this.availableExtensionsViewer.setLabelProvider(new CustomLabelProvider());
this.availableExtensionsViewer.setInput(this.availableExtensions);
// Add Button
this.addButton = new Button(this.container, SWT.PUSH);
this.addButton.setText("->");
this.addButton.setEnabled(false);
this.addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
ExportFileSettingsWizardPage.this.toExportExtensions
.addAll(ExportFileSettingsWizardPage.this.selectedExtensions);
ExportFileSettingsWizardPage.this.availableExtensions
.removeAll(ExportFileSettingsWizardPage.this.selectedExtensions);
ExportFileSettingsWizardPage.this.selectedExtensions.clear();
ExportFileSettingsWizardPage.this.availableExtensionsViewer
.setInput(ExportFileSettingsWizardPage.this.availableExtensions);
ExportFileSettingsWizardPage.this.availableExtensionsViewer.refresh();
ExportFileSettingsWizardPage.this.toExportExtensionsViewer
.setInput(ExportFileSettingsWizardPage.this.toExportExtensions);
ExportFileSettingsWizardPage.this.toExportExtensionsViewer.refresh();
setPageComplete(!ExportFileSettingsWizardPage.this.toExportExtensions.isEmpty());
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
// Available Extension Viewer
this.toExportExtensionsViewer = new TableViewer(this.container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
Table table1 = this.toExportExtensionsViewer.getTable();
GridData gd_table1 = new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 2);
gd_table1.minimumWidth = 300;
gd_table1.widthHint = 300;
table1.setLayoutData(gd_table1);
table1.setLinesVisible(true);
ColumnViewerToolTipSupport.enableFor(this.toExportExtensionsViewer);
this.toExportExtensionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ExportFileSettingsWizardPage.this.addButton.setEnabled(false);
ExportFileSettingsWizardPage.this.removeButton.setEnabled(true);
if (event.getSelection() instanceof IStructuredSelection) {
ExportFileSettingsWizardPage.this.selectedExtensions.clear();
IStructuredSelection iStructuredSelection = (IStructuredSelection) event.getSelection();
@SuppressWarnings("unchecked")
Iterator<Object> it = iStructuredSelection.iterator();
while (it.hasNext()) {
Object item = it.next();
if (item instanceof String) {
String extension = (String) item;
ExportFileSettingsWizardPage.this.selectedExtensions.add(extension);
String description = ExportFileSettingsWizardPage.this.iFileExporter
.getDescription(extension);
if (description == null)
description = "No description available.";
ExportFileSettingsWizardPage.this.txtDescription.setText(description);
}
}
}
}
});
TableViewerColumn tableViewerColumnItem_Name1 = new TableViewerColumn(this.toExportExtensionsViewer, SWT.NONE);
TableColumn trclmnItemName1 = tableViewerColumnItem_Name1.getColumn();
trclmnItemName1.setText("Extension");
trclmnItemName1.setWidth(100);
this.toExportExtensionsViewer.setContentProvider(new ArrayContentProvider());
this.toExportExtensionsViewer.setLabelProvider(new CustomLabelProvider());
this.toExportExtensionsViewer.setInput(this.toExportExtensions);
// RemoveSS Button
this.removeButton = new Button(this.container, SWT.PUSH);
this.removeButton.setText("<-");
this.removeButton.setEnabled(false);
this.removeButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
ExportFileSettingsWizardPage.this.toExportExtensions
.removeAll(ExportFileSettingsWizardPage.this.selectedExtensions);
ExportFileSettingsWizardPage.this.availableExtensions
.addAll(ExportFileSettingsWizardPage.this.selectedExtensions);
ExportFileSettingsWizardPage.this.selectedExtensions.clear();
ExportFileSettingsWizardPage.this.availableExtensionsViewer
.setInput(ExportFileSettingsWizardPage.this.availableExtensions);
ExportFileSettingsWizardPage.this.toExportExtensionsViewer
.setInput(ExportFileSettingsWizardPage.this.toExportExtensions);
setPageComplete(!ExportFileSettingsWizardPage.this.toExportExtensions.isEmpty());
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
Label lblDescription = new Label(this.container, SWT.NONE);
lblDescription.setText("Description :");
// Filler
new Label(this.container, SWT.NONE);
new Label(this.container, SWT.NONE);
this.txtDescription = new Text(this.container, SWT.MULTI);
GridData txtDescriptionGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
txtDescriptionGridData.minimumHeight = 100;
txtDescriptionGridData.heightHint = 100;
this.txtDescription.setLayoutData(txtDescriptionGridData);
setControl(this.container);
}
@Override
public boolean isPageComplete() {
return !this.toExportExtensions.isEmpty();
}
public List<String> getRequestedFileExtension() {
return this.toExportExtensions;
}
private class CustomLabelProvider extends ColumnLabelProvider {
@Override
public String getText(Object element) {
if (element instanceof String)
return (String) element;
else
return null;
}
}
}