package ru.runa.jbpm.ui.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.PlatformUI;
import org.jbpm.ui.PluginConstants;
import org.jbpm.ui.dialog.ExternalEditorDialog;
public class SetFormEditorAction extends BaseActionDelegate {
public void run(IAction action) {
Boolean enabled = action.isChecked();
IPreferenceStore preferenceStore = PlatformUI.getPreferenceStore();
if (enabled) {
String htmlEditorPath = preferenceStore.getString(PluginConstants.EXTERNAL_EDITOR_PREFERENCE_ID);
ExternalEditorDialog editorDialog = new ExternalEditorDialog(window.getShell(), htmlEditorPath);
if (editorDialog.open() == Dialog.OK) {
htmlEditorPath = editorDialog.getPath();
if (htmlEditorPath == null) {
htmlEditorPath = "";
}
preferenceStore.putValue(PluginConstants.EXTERNAL_EDITOR_PREFERENCE_ID, htmlEditorPath);
}
enabled = (htmlEditorPath.length() > 0);
} else {
enabled = false;
}
preferenceStore.putValue(PluginConstants.EXTERNAL_EDITOR_ENABLED, enabled.toString());
action.setChecked(enabled);
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
boolean enabled = PlatformUI.getPreferenceStore().getBoolean(PluginConstants.EXTERNAL_EDITOR_ENABLED);
action.setChecked(enabled);
}
}