| /** |
| * ******************************************************************************* |
| * 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 ExportPage extends WizardPage implements Listener { |
| |
| private Combo combo; |
| private Button browseButton; |
| private Button exportButton; |
| private File file = null; |
| private boolean export = false; |
| |
| protected ExportPage() { |
| super("Export"); |
| setTitle("Export"); |
| setDescription("Export settings to a configuration file"); |
| } |
| |
| public boolean doExport() { |
| return this.export; |
| } |
| |
| public void setFile(File file) { |
| this.file = file; |
| if(null != file) { |
| this.combo.setText(file.getAbsolutePath()); |
| } else { |
| this.combo.setText(""); |
| } |
| } |
| |
| public File getFile() { |
| return this.file; |
| } |
| |
| @Override |
| public void createControl(Composite parent) { |
| Composite container = new Composite(parent, SWT.NONE); |
| GridLayout layout = new GridLayout(); |
| container.setLayout(layout); |
| layout.numColumns = 3; |
| |
| exportButton = new Button(container, SWT.CHECK); |
| exportButton.setSelection(this.export); |
| exportButton.addListener(SWT.Selection, this); |
| |
| Label label = new Label(container, SWT.NONE); |
| label.setText("Enable Export"); |
| GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); |
| gridData.horizontalSpan = 2; |
| label.setLayoutData(gridData); |
| |
| label = new Label(container, SWT.NONE); |
| label.setText("To file: "); |
| |
| this.combo = new Combo(container, SWT.NONE); |
| combo.setText(""); |
| combo.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); |
| combo.setEnabled(this.export); |
| |
| this.browseButton = new Button(container, SWT.NONE); |
| browseButton.setText("Browse..."); |
| browseButton.addListener(SWT.Selection, this); |
| browseButton.setEnabled(this.export); |
| |
| setControl(container); |
| } |
| |
| @Override |
| public void handleEvent(Event event) { |
| if(SWT.Selection == event.type) { |
| if(this.browseButton == event.widget) { |
| Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| FileDialog fd = new FileDialog(shell, SWT.SAVE); |
| fd.setText("Export"); |
| String[] filterExt = { "*.rtmgc", "*.*" }; |
| fd.setFilterExtensions(filterExt); |
| String selected = fd.open(); |
| if(null != selected) { |
| this.combo.setText(selected); |
| file = new File(selected); |
| } |
| } else if(this.exportButton == event.widget) { |
| this.export = exportButton.getSelection(); |
| // disable/enable controls |
| this.combo.setEnabled(this.export); |
| this.browseButton.setEnabled(this.export); |
| } |
| } |
| } |
| } |