| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.preferences.ui.component; |
| |
| import java.io.File; |
| |
| import org.eclipse.core.filesystem.EFS; |
| import org.eclipse.core.filesystem.IFileStore; |
| import org.eclipse.jface.preference.FieldEditor; |
| import org.eclipse.jface.util.Assert; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.DisposeEvent; |
| import org.eclipse.swt.events.DisposeListener; |
| import org.eclipse.swt.events.FocusAdapter; |
| import org.eclipse.swt.events.FocusEvent; |
| import org.eclipse.swt.events.KeyAdapter; |
| import org.eclipse.swt.events.KeyEvent; |
| import org.eclipse.swt.events.SelectionEvent; |
| import org.eclipse.swt.events.SelectionListener; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Text; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.PartInitException; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.ide.IDE; |
| import org.eclipse.ui.internal.ide.dialogs.IFileStoreFilter; |
| |
| public class FileOpenCallEditor extends FieldEditor { |
| |
| private boolean isValid; |
| private String oldValue; |
| private String compTitle; |
| private Label title; |
| private Button fileOpenButton; |
| |
| protected FileOpenCallEditor() { |
| } |
| |
| public FileOpenCallEditor(String name, String labelText, Composite parent) { |
| init(name, labelText); |
| createControl(parent); |
| } |
| |
| protected boolean checkState() { |
| return true; |
| } |
| |
| protected boolean doCheckState() { |
| return true; |
| } |
| |
| @Override |
| protected void doFillIntoGrid(Composite parent, int numColumns) { |
| title = new Label(parent, SWT.UP); |
| title.setFont(parent.getFont()); |
| title.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); |
| title.setVisible(false); |
| |
| fileOpenButton = new Button(parent, SWT.PUSH); |
| GridData gd = new GridData(GridData.FILL_HORIZONTAL); |
| gd.widthHint = 100; |
| fileOpenButton.setLayoutData(gd); |
| fileOpenButton.setFont(parent.getFont()); |
| fileOpenButton.setText(getLabelText()); |
| fileOpenButton.addSelectionListener(new SelectionListener() { |
| |
| @Override |
| public void widgetSelected(SelectionEvent e) { |
| String fileName = getPreferenceStore().getString(getPreferenceName()); |
| File fileToOpen = new File(fileName); |
| |
| if (fileToOpen.exists() && fileToOpen.isFile()) { |
| IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI()); |
| IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| try { |
| IDE.openEditorOnFileStore( page, fileStore ); |
| } |
| catch (PartInitException e1) { |
| e1.printStackTrace(); |
| } |
| } |
| } |
| |
| @Override |
| public void widgetDefaultSelected(SelectionEvent e) { |
| } |
| }); |
| } |
| |
| @Override |
| protected void doLoad() { |
| } |
| |
| @Override |
| protected void doLoadDefault() { |
| } |
| |
| @Override |
| protected void doStore() { |
| } |
| |
| @Override |
| public int getNumberOfControls() { |
| return 2; |
| } |
| |
| public String getStringValue() { |
| return null; |
| } |
| |
| @Override |
| public boolean isValid() { |
| return true; |
| } |
| |
| @Override |
| protected void adjustForNumColumns(int numColumns) { |
| } |
| } |