Commit 0205ba24 authored by Liana Soima's avatar Liana Soima
Browse files

Listener classes created



New listeners are being implented + bugfix when setting to instantiated.
Signed-off-by: Liana Soima's avatarLiana Soima <soima@fortiss.org>
Issue-Ref: 3979
parent c0adec4b
......@@ -24,6 +24,7 @@ import static org.fortiss.tooling.kernel.ui.service.IContextMenuService.AFTER_GL
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
......@@ -96,14 +97,11 @@ public class SCElementIsInstantiated implements IContextMenuContributor {
return;
}
String textualInformation = selectedArgumentElement.getTextualInformation();
if(selectedArgumentElement.isToBeInstantiated() == true &&
!textualInformation.contains("{") &&
!textualInformation.contains("}")) {
selectedArgumentElement.setToBeInstantiated(false);
} else if(textualInformation.contains("{") ||
textualInformation.contains("}")) {
if(Pattern.matches("^\\{((.|\\n)*)}$", textualInformation)) {
openWarning(getCurrent().getActiveShell(), "",
"This element cannot be set as instantiated since its claim still contains uninstantiated words!");
} else {
selectedArgumentElement.setToBeInstantiated(false);
}
}
});
......
......@@ -16,6 +16,8 @@
package org.fortiss.af3.safetycases;
import org.eclipse.core.runtime.Plugin;
import org.fortiss.af3.safetycases.listener.AutomaticSetListenerPersistency;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.osgi.framework.BundleContext;
/**
......@@ -36,6 +38,9 @@ public class AF3SafetyCasesActivator extends Plugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
IPersistencyService ps = IPersistencyService.getInstance();
ps.addTopLevelElementListener(new AutomaticSetListenerPersistency());
}
/** {@inheritDoc} */
......
/*-------------------------------------------------------------------------+
| Copyright 2020 fortiss GmbH |
| |
| 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.af3.safetycases.listener;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.warning;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.safetycases.AF3SafetyCasesActivator;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
/**
* Listener that installs a {@link AutomaticSetListener} to {@link ITopLevelElement}s that are
* loaded
* at startup or during runtime.
*
* @author soima
*/
public class AutomaticSetListener extends EContentAdapter {
/** Holds the instance of the {@link AutomaticSetListener}. */
private volatile static AutomaticSetListener INSTANCE;
/** Constructor. */
private AutomaticSetListener() {
// Prevents direct instantiation.
}
/** The instance (singleton) of the {@link AutomaticSetListener}. */
public static synchronized AutomaticSetListener getInstance() {
if(INSTANCE == null) {
INSTANCE = new AutomaticSetListener();
}
return INSTANCE;
}
/**
* Installs {@code this} renaming listener to all that reside
* below the passed {@link ITopLevelElement}.
*/
public static void installRenamingListeners(ITopLevelElement element) {
EObject rootElement = element.getRootModelElement();
if(!(rootElement instanceof FileProject)) {
warning(AF3SafetyCasesActivator.getDefault(),
"Got a root element that is not a file project while trying to install " +
"listeners. This could indicate a model corruption.");
return;
}
FileProject fileProject = (FileProject)rootElement;
}
/** {@inheritDoc} */
@Override
public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
if(notification.getNotifier() instanceof ArgumentElement &&
notification.getEventType() == Notification.SET) {
// Input checks.
if(!(notification.getFeature() instanceof EAttribute)) {
return;
}
EAttribute attribute = (EAttribute)notification.getFeature();
if(!attribute.getName().equals("name")) {
// Only act upon renaming, not other modifications.
return;
}
}
}
}
/*-------------------------------------------------------------------------+
| Copyright 2020 fortiss GmbH |
| |
| 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.af3.safetycases.listener;
import static org.fortiss.af3.safetycases.listener.AutomaticSetListener.installRenamingListeners;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.listener.IPersistencyServiceListener;
/**
*
* @author liana
*/
public class AutomaticSetListenerPersistency implements IPersistencyServiceListener {
/** {@inheritDoc} */
@Override
public void topLevelElementLoaded(ITopLevelElement element) {
installRenamingListeners(element);
}
/** {@inheritDoc} */
@Override
public void topLevelElementAdded(ITopLevelElement element) {
installRenamingListeners(element);
}
/** {@inheritDoc} */
@Override
public void topLevelElementRemoved(ITopLevelElement element) {
// ignore
}
/** {@inheritDoc} */
@Override
public void topLevelElementContentChanged(ITopLevelElement element) {
installRenamingListeners(element);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment