Skip to main content
summaryrefslogtreecommitdiffstats
blob: daa9aa2a1bdda7372dd1b5efc0ef58293de2bdd2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************************************
 * Copyright (c) 2006, 2009 Oracle. 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:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.ui.internal.selection;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jpt.ui.internal.views.JpaDetailsView;
import org.eclipse.jpt.ui.internal.views.structure.JpaStructureView;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.ITextEditor;

/**
 * Factory to build adapters for a workbench part:
 *   - JPA selection participant (if the editor part is a text editor etc.)
 * 
 * See org.eclipse.jpt.ui plugin.xml.
 */
public class WorkbenchPartAdapterFactory 
	implements IAdapterFactory
{
	private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaSelectionParticipant.class };

	public Class<?>[] getAdapterList() {
		return ADAPTER_LIST;
	}

	public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) {
		if (adaptableObject instanceof IWorkbenchPart) {
			return this.getAdapter((IWorkbenchPart) adaptableObject, adapterType);
		}
		return null;
	}

	private Object getAdapter(IWorkbenchPart workbenchPart, Class<?> adapterType) {
		if (adapterType == JpaSelectionParticipant.class) {
			return this.buildJpaSelectionParticipant(workbenchPart);
		}
		return null;
	}

	private JpaSelectionParticipant buildJpaSelectionParticipant(IWorkbenchPart workbenchPart) {
		JpaSelectionManager selectionManager = SelectionManagerFactory.getSelectionManager(workbenchPart.getSite().getWorkbenchWindow());
		if (workbenchPart instanceof ITextEditor) {
			return new TextEditorSelectionParticipant(selectionManager, (ITextEditor) workbenchPart);
		}
		if (workbenchPart instanceof JpaStructureView) {
			return new JpaStructureSelectionParticipant(selectionManager, (JpaStructureView) workbenchPart);
		}
		if (workbenchPart instanceof JpaDetailsView) {
			return new JpaDetailsSelectionParticipant((JpaDetailsView) workbenchPart);
		}
		return null;
	}

}

Back to the top