Skip to content
Snippets Groups Projects
Commit 58c55416 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

kernel refactoring: extract ui components

parent 9168ddbc
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,6 @@ package org.fortiss.tooling.kernel.internal.storage.eclipse;
import java.util.Collection;
import org.conqat.ide.commons.ui.logging.LoggingUtils;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
......@@ -29,6 +28,7 @@ import org.eclipse.emf.transaction.Transaction;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.util.LoggingUtils;
/**
* This class wraps another EMF command and makes sure that all execute methods
......
......@@ -24,8 +24,6 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import org.conqat.ide.commons.ui.dialog.MessageUtils;
import org.conqat.ide.commons.ui.logging.LoggingUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
......@@ -36,11 +34,11 @@ import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swt.widgets.Display;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.interfaces.IStorageProvider;
import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext;
import org.fortiss.tooling.kernel.services.IPersistencyService;
import org.fortiss.tooling.kernel.util.LoggingUtils;
/**
* This class implements the persistency service behavior for Eclipse file
......@@ -138,39 +136,41 @@ public class EclipseResourceStorageProvider implements IResourceChangeListener,
private void handleChange(final IFile file) {
final ModelContext context = loadedContexts.get(file);
if (!context.getLastChangeWasIntended()) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final boolean reload = MessageUtils.askQuestion(
"Reload changed file?",
"The file "
+ file.getName()
+ " changed on disk. "
+ "Load these changes? "
+ "Note that loading the changes will discard all editors, "
+ "so all unsaved changes and the undo history will be lost. "
+ "However if you do not reload now, "
+ "the contents of the file will be overwritten "
+ "the next time you perform a save.");
if (reload) {
unloadContext(file);
try {
loadContext(file).setLastChangeWasIntended();
// perform touch to make sure the viewer does a
// refresh
file.touch(null);
} catch (final Exception e) {
LoggingUtils.error(
ToolingKernelActivator.getDefault(),
"Had an error during reloading the file!",
e);
}
}
// TODO (FH): find a solution for this ui code
// Display.getDefault().asyncExec(new Runnable() {
// @Override
// public void run() {
// final boolean reload = true;
// // MessageUtils.askQuestion(
// // "Reload changed file?",
// // "The file "
// // + file.getName()
// // + " changed on disk. "
// // + "Load these changes? "
// // +
// // "Note that loading the changes will discard all editors, "
// // +
// // "so all unsaved changes and the undo history will be lost. "
// // + "However if you do not reload now, "
// // + "the contents of the file will be overwritten "
// // + "the next time you perform a save.");
//
// if (reload) {
// }
//
// }
// });
unloadContext(file);
try {
loadContext(file).setLastChangeWasIntended();
}
});
// perform touch to make sure the viewer does a
// refresh
file.touch(null);
} catch (final Exception e) {
LoggingUtils.error(ToolingKernelActivator.getDefault(),
"Had an error during reloading the file!", e);
}
}
}
......
......@@ -21,15 +21,12 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.conqat.ide.commons.ui.logging.LoggingUtils;
import org.conqat.lib.commons.collections.IdentityHashSet;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
......@@ -46,12 +43,12 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.transaction.TransactionalCommandStack;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.ui.IEditorPart;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext;
import org.fortiss.tooling.kernel.model.IIdLabeled;
import org.fortiss.tooling.kernel.services.IModelElementService;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.util.EMFResourceUtils;
import org.fortiss.tooling.kernel.util.LoggingUtils;
/**
* The model context provides additional commands and hooks for a model.
......@@ -79,12 +76,6 @@ class ModelContext implements ITopLevelElementContext {
/** The transactional command stack. */
private final AutoUndoCommandStack transactionalCommandStack;
/**
* Set of editors which depend on this context. These editors are closed
* when the underlying file is deleted or changed.
*/
private final Set<IEditorPart> dependentEditors = new IdentityHashSet<IEditorPart>();
/** Flag for remembering whether the last change of the file was intended. */
private boolean lastChangeWasIntended = false;
......@@ -204,35 +195,11 @@ class ModelContext implements ITopLevelElementContext {
}
}
/**
* Add a dependent editor part which will be closed when this context
* becomes invalid.
*/
/* package */void addDependentEditor(IEditorPart editor) {
dependentEditors.add(editor);
}
/** Removes an editor added via {@link #addDependentEditor(IEditorPart)}. */
/* package */void removeDependentEditor(IEditorPart editor) {
dependentEditors.remove(editor);
}
/** Destroys this context and closes all dependent editors. */
public void destroy() {
// discard changes
((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
List<IEditorPart> editors = new ArrayList<IEditorPart>(dependentEditors);
dependentEditors.clear();
for (final IEditorPart editor : editors) {
editor.getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
editor.getSite().getPage().closeEditor(editor, false);
}
});
}
}
/** Returns the file associated with this model. */
......@@ -377,10 +344,11 @@ class ModelContext implements ITopLevelElementContext {
children = result.eContents();
}
for (final EObject e : children) {
if (namePart.equals(IModelElementService.INSTANCE
.getModelElementHandler(e).getName(e))) {
result = e;
continue OUTER;
if (e instanceof INamedElement) {
if (namePart.equals(((INamedElement) e).getName())) {
result = e;
continue OUTER;
}
}
}
return null;
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2005-2010 Technische Universitaet Muenchen |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.osgi.framework.Bundle;
/**
* Utility methods for the extension points of plug-ins.
*
* Note: This class originates form the org.conqat.ide.commons.ui
* implementation. It re-packaged with the kernel to avoid any dependency to
* eclipse.ui packages. See http://www.conqat.org for the original version.
*
* @author hummelb
* @author $Author$
* @version $Rev$
* @levd.rating GREEN Hash: 3A6C32DF7541A73EFF1BBA7204FFB23D
*/
public class ExtensionPointUtils {
/** Load the given class and throws an exception in case of problems. */
public static Class<?> loadClass(String className, Bundle bundle)
throws ClassNotFoundException {
if (className == null) {
throw new ClassNotFoundException("Class name not configured.");
}
return bundle.loadClass(className);
}
/** Returns the bundle an extension is declared in. */
public static Bundle getBundle(IConfigurationElement configElement) {
Bundle bundle = Platform.getBundle(configElement
.getDeclaringExtension().getNamespaceIdentifier());
return bundle;
}
/**
* Returns the {@link IConfigurationElement}s for a given extension point
* and element name.
*/
@SuppressWarnings("unchecked")
public static List<IConfigurationElement> getConfigurationElements(
String extensionPointName, String configurationElementName) {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
.getExtensionPoint(extensionPointName);
if (extensionPoint == null) {
LoggingUtils.log(ToolingKernelActivator.getDefault(),
"Could not find extension point " + extensionPointName,
IStatus.ERROR);
return Collections.EMPTY_LIST;
}
List<IConfigurationElement> configurationElements = new ArrayList<IConfigurationElement>();
for (IExtension e : extensionPoint.getExtensions()) {
for (IConfigurationElement ce : e.getConfigurationElements()) {
if (ce.getName().equals(configurationElementName)) {
configurationElements.add(ce);
}
}
}
return configurationElements;
}
}
\ No newline at end of file
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2005-2010 Technische Universitaet Muenchen |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.util;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
/**
* Utility code for performing logging.
*
* Note: This class originates form the org.conqat.ide.commons.ui
* implementation. It re-packaged with the kernel to avoid any dependency to
* eclipse.ui packages. See http://www.conqat.org for the original version.
*
* @author hummelb
* @author schwitze
* @author $Author$
* @version $Rev$
* @levd.rating GREEN Hash: AA5D7661DFC5CC4BF4D59C1A84E5D471
*/
public class LoggingUtils {
/**
* Logs a message that occurred in the context of the given plug-in with the
* given severity.
*
* @see IStatus
*
* @param plugin
* The plug-in that logs the message in its context.
* @param message
* The message text to log.
* @param severity
* The severity of the log message. See {@link IStatus} for valid
* constants.
*
*/
public static void log(Plugin plugin, String message, int severity) {
log(plugin, message, severity, null);
}
/**
* Logs a message that occurred in the context of the given plug-in with the
* given severity and a given {@link Throwable} that originally caused this
* log message.
*
* @see IStatus
*
* @param plugin
* The plug-in that logs the message in its context.
* @param message
* The message text to log.
* @param severity
* The severity of the log message. See {@link IStatus} for valid
* constants.
* @param cause
* The {@link Throwable} that originally caused this log message.
*/
public static void log(Plugin plugin, String message, int severity,
Throwable cause) {
String pluginId = plugin.getBundle().getSymbolicName();
IStatus status = new Status(severity, pluginId, message, cause);
plugin.getLog().log(status);
}
/**
* Logs an exception that occurred in the context of the given plug-in with
* the severity {@link IStatus#ERROR}.
*
* @param plugin
* The plug-in that logs the message in its context.
* @param message
* The message text to log.
* @param cause
* The {@link Throwable} that originally caused this log message.
*/
public static void error(Plugin plugin, String message, Throwable cause) {
log(plugin, message, IStatus.ERROR, cause);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment