blob: 9447aea94f2bbd8d2fa296a731e434325db15540 [file] [log] [blame]
/**
* *******************************************************************************
* Copyright (c) 2017 Timing-Architects Embedded Systems GmbH 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:
* Timing-Architects Embedded Systems GmbH - initial API and implementation
*
* *******************************************************************************
*/
package org.eclipse.app4mc.amalthea.generator.ui;
import java.io.File;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
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.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
public class ImportPage extends WizardPage implements Listener {
private Combo combo;
private Button button;
protected ImportPage() {
super("Import");
setTitle("Import");
setDescription("Import settings from an existing configuration file");
}
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 3;
Label label = new Label(container, SWT.NONE);
label.setText("From file: ");
this.combo = new Combo(container, SWT.NONE);
combo.setText("");
combo.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
button = new Button(container, SWT.NONE);
button.setText("Browse...");
button.addListener(SWT.Selection, this);
setControl(container);
}
@Override
public void handleEvent(Event event) {
if(this.button == event.widget) {
if(SWT.Selection == event.type) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
FileDialog fd = new FileDialog(shell, SWT.OPEN);
fd.setText("Import");
String[] filterExt = { "*.rtmgc", "*.*" };
fd.setFilterExtensions(filterExt);
String selected = fd.open();
File file = null;
if(null != selected) {
this.combo.setText(selected);
file = new File(selected);
}
// update configurationPage
ConfigurationPage configurationPage = (ConfigurationPage) getWizard().getPage("Configuration");
configurationPage.loadConfiguration(file);
// update exportPage
ExportPage exportPage = (ExportPage) getWizard().getPage("Export");
exportPage.setFile(file);
}
}
}
}