| /******************************************************************************* |
| * Copyright (c) 2012 EclipseSource Muenchen GmbH. |
| * |
| * 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: |
| ******************************************************************************/ |
| package org.eclipse.emf.emfstore.client.ui.errorreporting; |
| |
| import java.io.File; |
| |
| import org.eclipse.jface.preference.DirectoryFieldEditor; |
| import org.eclipse.jface.preference.FieldEditorPreferencePage; |
| import org.eclipse.jface.util.PropertyChangeEvent; |
| import org.eclipse.ui.IWorkbench; |
| import org.eclipse.ui.IWorkbenchPreferencePage; |
| |
| /** |
| * Preference page for error reporting feature. |
| * |
| * @author emueller |
| * |
| */ |
| public class ErrorReportingPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { |
| |
| private DirectoryFieldEditor zipPathEditor; |
| |
| /** |
| * Default constructor. |
| */ |
| public ErrorReportingPreferencePage() { |
| super(GRID); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public void init(IWorkbench workbench) { |
| setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
| getPreferenceStore().setDefault(ErrorReportingPreferences.ZIP_PATH_KEY, |
| ErrorReportingPreferences.ZIP_PATH_DEFAULT); |
| } |
| |
| private boolean validateZipPath(String zipPath) { |
| return new File(zipPath).exists(); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| protected void createFieldEditors() { |
| zipPathEditor = new DirectoryFieldEditor(ErrorReportingPreferences.ZIP_PATH_KEY, "&Zip path:", |
| getFieldEditorParent()); |
| addField(zipPathEditor); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| protected void checkState() { |
| |
| super.checkState(); |
| boolean validZipPath = validateZipPath(zipPathEditor.getStringValue()); |
| |
| if (validZipPath) { |
| setValid(true); |
| setErrorMessage(null); |
| } else { |
| setValid(false); |
| setErrorMessage("Invalid zip path. \n"); |
| } |
| |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public void propertyChange(PropertyChangeEvent event) { |
| |
| if (event.getProperty().equals("field_editor_value")) { |
| checkState(); |
| } |
| |
| } |
| } |