Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Resolve circular dependency between org.eclipse.mylyn.monitor.* and
Browse files Browse the repository at this point in the history
org.eclipse.mylyn.context.*

eclipse-mylyn/org.eclipse.mylyn.commons#16
  • Loading branch information
BeckerFrank committed Nov 28, 2022
1 parent 5e913e3 commit 3bb49e0
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 202 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
/*******************************************************************************
* Copyright (c) 2004, 2011 Mylyn project committers and others.
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
*******************************************************************************/

package org.eclipse.mylyn.internal.cdt.ui;

import java.util.Iterator;

import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.monitor.ui.AbstractUserInteractionMonitor;
import org.eclipse.mylyn.context.core.AbstractContextInteractionMonitor;
import org.eclipse.ui.IWorkbenchPart;

/**
* @author Mik Kersten
* @author Jeff Johnston
*/
public class CDTEditorMonitor extends AbstractUserInteractionMonitor {
public class CDTEditorMonitor extends AbstractContextInteractionMonitor {

protected ICElement lastSelectedElement = null;

Expand Down Expand Up @@ -59,8 +57,7 @@ public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selecti

// Object selectedObject =
// structuredSelection.getFirstElement();
for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
Object selectedObject = iterator.next();
for (Object selectedObject : structuredSelection) {
if (selectedObject instanceof ICElement) {
ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary((ICElement) selectedObject);
if (checkedElement == null) {
Expand Down
7 changes: 5 additions & 2 deletions org.eclipse.mylyn.context.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ Bundle-SymbolicName: org.eclipse.mylyn.context.core;singleton:=true
Bundle-Version: 3.26.0.qualifier
Bundle-Activator: org.eclipse.mylyn.internal.context.core.ContextCorePlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.mylyn.commons.core;bundle-version="[3.8.0,4.0.0)",
org.eclipse.mylyn.monitor.core;bundle-version="[3.8.0,4.0.0)"
org.eclipse.mylyn.monitor.core;bundle-version="[3.8.0,4.0.0)",
org.eclipse.mylyn.monitor.ui;bundle-version="3.26.0",
org.eclipse.mylyn.commons.context;bundle-version="3.26.0"
Import-Package: org.apache.commons.io;version="[1.4.0,3.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*******************************************************************************
* Copyright (c) 2022 Tasktop Technologies and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/

package org.eclipse.mylyn.context.core;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.mylyn.internal.monitor.ui.IMonitoredWindow;
import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin;
import org.eclipse.mylyn.monitor.core.InteractionEvent;
import org.eclipse.mylyn.monitor.ui.AbstractUserInteractionMonitor;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;

/**
* @since 3.26
*/
public abstract class AbstractContextInteractionMonitor extends AbstractUserInteractionMonitor {

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part.getSite() != null && part.getSite().getWorkbenchWindow() != null) {
IWorkbenchWindow window = part.getSite().getWorkbenchWindow();
if (window instanceof IMonitoredWindow && !((IMonitoredWindow) window).isMonitored()) {
return;
}
}
if (selection == null || selection.isEmpty()) {
return;
}
if (!ContextCore.getContextManager().isContextActive()) {
handleWorkbenchPartSelection(part, selection, false);
} else {
handleWorkbenchPartSelection(part, selection, true);
}
}

/**
* Intended to be called back by subclasses.
*/
@Override
protected void handleNavigation(IWorkbenchPart part, Object targetElement, String kind,
boolean contributeToContext) {
handleNavigation(part.getSite().getId(), targetElement, kind, contributeToContext);
}

/**
* Intended to be called back by subclasses. *
*
* @since 3.1
*/
@Override
protected void handleNavigation(String partId, Object targetElement, String kind, boolean contributeToContext) {
AbstractContextStructureBridge adapter = ContextCore.getStructureBridge(targetElement);
if (adapter.getContentType() != null) {
String handleIdentifier = adapter.getHandleIdentifier(targetElement);
InteractionEvent navigationEvent = new InteractionEvent(InteractionEvent.Kind.SELECTION,
adapter.getContentType(), handleIdentifier, partId, kind);
if (handleIdentifier != null && contributeToContext) {
ContextCore.getContextManager().processInteractionEvent(navigationEvent);
}
MonitorUiPlugin.getDefault().notifyInteractionObserved(navigationEvent);
}
}

/**
* Intended to be called back by subclasses.
*
* @since 3.1
*/
@Override
protected void handleElementEdit(String partId, Object selectedElement, boolean contributeToContext) {
if (selectedElement == null) {
return;
}
AbstractContextStructureBridge bridge = ContextCore.getStructureBridge(selectedElement);
String handleIdentifier = bridge.getHandleIdentifier(selectedElement);
InteractionEvent editEvent = new InteractionEvent(InteractionEvent.Kind.EDIT, bridge.getContentType(),
handleIdentifier, partId);
if (handleIdentifier != null && contributeToContext) {
ContextCore.getContextManager().processInteractionEvent(editEvent);
}
MonitorUiPlugin.getDefault().notifyInteractionObserved(editEvent);
}

/**
* Intended to be called back by subclasses. *
*
* @since 3.1
*/
@Override
protected InteractionEvent handleElementSelection(String partId, Object selectedElement,
boolean contributeToContext) {
if (selectedElement == null || selectedElement.equals(lastSelectedElement)) {
return null;
}
AbstractContextStructureBridge bridge = ContextCore.getStructureBridge(selectedElement);
String handleIdentifier = bridge.getHandleIdentifier(selectedElement);
InteractionEvent selectionEvent;
if (bridge.getContentType() != null) {
selectionEvent = new InteractionEvent(InteractionEvent.Kind.SELECTION, bridge.getContentType(),
handleIdentifier, partId);
} else {
selectionEvent = new InteractionEvent(InteractionEvent.Kind.SELECTION, null, null, partId);
}
if (handleIdentifier != null && contributeToContext) {
ContextCore.getContextManager().processInteractionEvent(selectionEvent);
}
MonitorUiPlugin.getDefault().notifyInteractionObserved(selectionEvent);
return selectionEvent;
}

/**
* Intended to be called back by subclasses.
*/
@Override
protected InteractionEvent handleElementSelection(IWorkbenchPart part, Object selectedElement,
boolean contributeToContext) {
return handleElementSelection(part.getSite().getId(), selectedElement, contributeToContext);
}

/**
* Intended to be called back by subclasses.
*/
@Override
protected void handleElementEdit(IWorkbenchPart part, Object selectedElement, boolean contributeToContext) {
handleElementEdit(part.getSite().getId(), selectedElement, contributeToContext);
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2004, 2012 Tasktop Technologies and others.
*
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Tasktop Technologies - initial API and implementation
Expand Down Expand Up @@ -32,18 +32,21 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.common.context.CommonContextPlugin;
import org.eclipse.mylyn.common.context.ContextCallBack;
import org.eclipse.mylyn.commons.core.ExtensionPointReader;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.context.core.AbstractContextContributor;
import org.eclipse.mylyn.context.core.AbstractContextStructureBridge;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.context.core.IContextContributor;
import org.eclipse.mylyn.context.core.IInteractionContextScaling;
import org.eclipse.mylyn.monitor.core.InteractionEvent;
import org.osgi.framework.BundleContext;

/**
* Activator for the Context Core plug-in.
*
*
* @author Mik Kersten
* @since 3.0
*/
Expand Down Expand Up @@ -156,6 +159,21 @@ public void start(BundleContext context) throws Exception {
}
contextStore.setContextDirectory(storeFile);
contextManager = new InteractionContextManager(contextStore);
CommonContextPlugin.getDefault().setContextCallBack(new ContextCallBack() {

@Override
public void processActivityMetaContextEvent(InteractionEvent event) {
ContextCorePlugin.getContextManager().processActivityMetaContextEvent(event);
}

@Override
public String getActiveContextHandleIdentifier() {
if (ContextCore.getContextManager().getActiveContext().getHandleIdentifier() != null) {
return ContextCore.getContextManager().getActiveContext().getHandleIdentifier();
}
return null;
}
});
}

@Override
Expand Down Expand Up @@ -254,7 +272,7 @@ public void removeContextContributor(AbstractContextContributor contributor) {

/**
* Finds the shadowed content for the passed in base content
*
*
* @param baseContent
* @return the shadowed content type or if null there is none
*/
Expand Down Expand Up @@ -427,7 +445,8 @@ public static void initExtensions() {
if (!extensionsRead) {
IExtensionRegistry registry = Platform.getExtensionRegistry();

IExtensionPoint extensionPoint = registry.getExtensionPoint(BridgesExtensionPointReader.EXTENSION_ID_CONTEXT);
IExtensionPoint extensionPoint = registry
.getExtensionPoint(BridgesExtensionPointReader.EXTENSION_ID_CONTEXT);
IExtension[] extensions = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] elements = extension.getConfigurationElements();
Expand All @@ -450,7 +469,8 @@ public static void initExtensions() {
}
}

extensionPoint = registry.getExtensionPoint(BridgesExtensionPointReader.EXTENSION_ID_RELATION_PROVIDERS);
extensionPoint = registry
.getExtensionPoint(BridgesExtensionPointReader.EXTENSION_ID_RELATION_PROVIDERS);
extensions = extensionPoint.getExtensions();
for (IExtension extension : extensions) {
IConfigurationElement[] elements = extension.getConfigurationElements();
Expand All @@ -476,15 +496,16 @@ private static void readBridge(IConfigurationElement element) {

AbstractContextStructureBridge bridge = (AbstractContextStructureBridge) object;
if (element.getAttribute(BridgesExtensionPointReader.ATTR_PARENT_CONTENT_TYPE) != null) {
String parentContentType = element.getAttribute(BridgesExtensionPointReader.ATTR_PARENT_CONTENT_TYPE);
String parentContentType = element
.getAttribute(BridgesExtensionPointReader.ATTR_PARENT_CONTENT_TYPE);
if (parentContentType != null) {
bridge.setParentContentType(parentContentType);
}
}
ContextCorePlugin.getDefault().addStructureBridge(bridge);
} catch (Throwable e) {
StatusHandler.log(new Status(IStatus.WARNING, ContextCorePlugin.ID_PLUGIN,
"Could not load bridge extension", e)); //$NON-NLS-1$
StatusHandler.log(
new Status(IStatus.WARNING, ContextCorePlugin.ID_PLUGIN, "Could not load bridge extension", e)); //$NON-NLS-1$
}
}

Expand All @@ -495,15 +516,17 @@ private static void readInternalBridge(IConfigurationElement element) {
if (baseContent == null || shadowedByContent == null) {
StatusHandler.log(new Status(IStatus.WARNING, ContextCorePlugin.ID_PLUGIN,
"Ignoring bridge shadowing because of invalid extension point " //$NON-NLS-1$
+ BridgesExtensionPointReader.ELEMENT_STRUCTURE_BRIDGE, new Exception()));
+ BridgesExtensionPointReader.ELEMENT_STRUCTURE_BRIDGE,
new Exception()));
}
ContextCorePlugin.getDefault().addShadowsContent(baseContent, shadowedByContent);
}

private static void readRelationProvider(IConfigurationElement element) {
try {
String contentType = element.getAttribute(BridgesExtensionPointReader.ATTR_CONTENT_TYPE);
AbstractRelationProvider relationProvider = (AbstractRelationProvider) element.createExecutableExtension(BridgesExtensionPointReader.ATTR_CLASS);
AbstractRelationProvider relationProvider = (AbstractRelationProvider) element
.createExecutableExtension(BridgesExtensionPointReader.ATTR_CLASS);
if (contentType != null) {
ContextCorePlugin.getDefault().addRelationProvider(contentType, relationProvider);
}
Expand Down
Loading

0 comments on commit 3bb49e0

Please sign in to comment.