diff options
author | Henrik Rentz-Reichert | 2014-09-11 15:43:42 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2014-09-11 15:43:42 +0000 |
commit | d946f4692718b3694d906c918f623c496f771760 (patch) | |
tree | 07a9c9be5956a7bf46920959c4546e22d07f4a83 /plugins/org.eclipse.etrice.core.common.ui | |
parent | 86b3d9fa204a7388b4a0bc0650556a9222331a06 (diff) | |
download | org.eclipse.etrice-d946f4692718b3694d906c918f623c496f771760.tar.gz org.eclipse.etrice-d946f4692718b3694d906c918f623c496f771760.tar.xz org.eclipse.etrice-d946f4692718b3694d906c918f623c496f771760.zip |
[core.common.ui] moved IValidatingEditor and SaveOnFocusLostListener to
this plug-in
Diffstat (limited to 'plugins/org.eclipse.etrice.core.common.ui')
2 files changed, 102 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/IValidatingEditor.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/IValidatingEditor.java new file mode 100644 index 000000000..8e31c6fcc --- /dev/null +++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/IValidatingEditor.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * 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: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.common.ui.editor; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface IValidatingEditor { + + public boolean isValid(); +} diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java new file mode 100644 index 000000000..b2658c689 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/editor/SaveOnFocusLostListener.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * 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: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.common.ui.editor; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.xtext.ui.editor.XtextEditor; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class SaveOnFocusLostListener implements IPartListener { + + private XtextEditor editor; + private String store; + private String key; + + public SaveOnFocusLostListener(XtextEditor editor, String store, String key) { + this.editor = editor; + this.store = store; + this.key = key; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart) + */ + @Override + public void partActivated(IWorkbenchPart part) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart) + */ + @Override + public void partBroughtToTop(IWorkbenchPart part) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart) + */ + @Override + public void partClosed(IWorkbenchPart part) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart) + */ + @Override + public void partDeactivated(IWorkbenchPart part) { + if (!(editor instanceof IValidatingEditor)) + return; + + boolean save = Platform.getPreferencesService().getBoolean(store, key, false, null); + + if (save && editor.isDirty()) + if (((IValidatingEditor)editor).isValid()) + editor.doSave(new NullProgressMonitor()); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart) + */ + @Override + public void partOpened(IWorkbenchPart part) { + } + +} |