@Override public void stop(BundleContext context) throws Exception { remoteBookmarksTreeChangeEventHandler.unsubscribe(); bookmarksSaver.close(); IAdapterManager adapterManager = Platform.getAdapterManager(); adapterManager.unregisterAdapters(bookmarkAdapterFactory); bookmarkProblemsAutoUpdater.close(); pathPlaceholdersStore.close(); bookmarksMarkers.close(); mostVisitedBookmarks.close(); numberedBookmarks.close(); recentBookmarks.close(); bookmarkProblems.close(); plugin = null; super.stop(context); }
/** * Returns an instance of the adaptable object with type of adapterType, or * null if the given object could not be adapted to that type. See * {@link IAdapterManager#getAdapter(Object, Class)}. */ @SuppressWarnings("unchecked") public static <T> T getAdapter(Object adaptable, Class<? extends T> adapterType) { /* * Try a simple instanceof check. This also safeguards against a misuse of * getAdapter. For example, ISelection is adaptable (there is a * SelectionAdapterFactory), so the user may incorrectly try adapting it to * IStructuredSelection. However, in this case, the implementation of * SelectionAdapterFactory would return null. */ if (adapterType.isInstance(adaptable)) { return (T) adaptable; } IAdapterManager adapterManager = Platform.getAdapterManager(); assert (adapterManager != null); return (T) adapterManager.getAdapter(adaptable, adapterType); }
@Override public final Object execute(final ExecutionEvent event) { final List<String> arguments = new ArrayList<String>(); final String command = Activator.getDefault().getPreferenceStore().getString(this.getMergeCommandPathName()); final TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); if (selection.isEmpty() == false) { final IAdapterManager adapterManager = Platform.getAdapterManager(); final IResource resource = adapterManager.getAdapter(selection.getFirstElement(), IResource.class); if (resource != null) { arguments.add("/patchpath:" + resource.getLocation().toString()); ProcessWrapper.executeCommand(command, arguments); } } return null; }
private static SaveToServerActionController buildController(final IStructuredSelection selection) { final IAdapterManager adapterManager = Platform.getAdapterManager(); final List<IResource> selectedResources = new ArrayList<>(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { final IResource selectedResource = (IResource) adapterManager.getAdapter(iterator.next(), IResource.class); if (null != selectedResource) { selectedResources.add(selectedResource); } } final List<IResource> filteredResources = filter(selectedResources); if (filteredResources.isEmpty()) return null; final IProject project = filteredResources.get(0).getProject(); for (final IResource resource : filteredResources) { if (!project.equals(resource.getProject())) { logger.warn("Unable to save resources from multiple projects at the same time. Only saving resources from " + project.getName()); break; } } return buildController(selection, filteredResources, project); }
@Override public void start(final BundleContext context) throws Exception { super.start(context); plugin = this; teamBuildAdapterFactory = new TeamBuildAdapterFactory(); final IAdapterManager manager = Platform.getAdapterManager(); manager.registerAdapters(teamBuildAdapterFactory, IQueuedBuild.class); manager.registerAdapters(teamBuildAdapterFactory, IBuildDetail.class); }
public void startup(IProgressMonitor monitor) throws CoreException { IAdapterManager mgr = Platform.getAdapterManager(); // adapterFactory to translate IResource to ISVNResource localResourceAdapterFactory = new LocalResourceAdapterFactory(); mgr.registerAdapters(localResourceAdapterFactory,IResource.class); }
/** * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ public <T> T getAdapter(Class<T> adapter) { // lookup the IAdapterManager service final IAdapterManager manager = Platform.getAdapterManager(); // forward the request to IAdapterManager service return manager.getAdapter(this, adapter); }
/** * This method is called upon plug-in activation. * * @param context * the context * * @throws Exception * the exception */ @Override public void start(BundleContext context) throws Exception { super.start(context); IAdapterManager manager = Platform.getAdapterManager(); manager.registerAdapters(new ContentOutlinePageAdapterFactory(), DiagramEditor.class); // Initialize the image cache imageCache = new ImageCache(); }
@Override public void start(BundleContext context) throws Exception { super.start(context); IAdapterManager manager = Platform.getAdapterManager(); breakpointWorkbenchAdapterFactory = new ChromiumBreakpointWBAFactory(); manager.registerAdapters(breakpointWorkbenchAdapterFactory, ChromiumLineBreakpoint.class); plugin = this; JavascriptVmFactory.getRootLogger().addHandler(SDK_LOG_HANDLER); }
@Override public void stop(BundleContext context) throws Exception { JavascriptVmFactory.getRootLogger().removeHandler(SDK_LOG_HANDLER); plugin = null; IAdapterManager manager = Platform.getAdapterManager(); manager.unregisterAdapters(breakpointWorkbenchAdapterFactory); super.stop(context); }
private ChromiumLineBreakpoint getBreakpoint() { IAdapterManager manager= Platform.getAdapterManager(); IAdaptable adaptable = getElement(); ChromiumLineBreakpoint adapted = (ChromiumLineBreakpoint) manager.getAdapter(adaptable, ChromiumLineBreakpoint.class); return adapted; }
@Override public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { boolean result = false; if ((receiver != null) && (expectedValue != null)) { int expectedType = IResource.NONE; if (expectedValue.toString().toUpperCase().equals("IResource.FILE".toUpperCase())) { expectedType = IResource.FILE; } else if (expectedValue.toString().toUpperCase().equals("IResource.FOLDER".toUpperCase())) { expectedType = IResource.FOLDER; } else if (expectedValue.toString().toUpperCase().equals("IResource.PROJECT".toUpperCase())) { expectedType = IResource.PROJECT; } else { // Invalid or unknown expected value return false; } final IAdapterManager adapterManager = Platform.getAdapterManager(); if (adapterManager != null) { // Check if selected item is of expected type final IResource resource = adapterManager.getAdapter(receiver, IResource.class); if ((resource != null) && ((resource.getType() & expectedType) != IResource.NONE)) { result = true; } } } return result; }
@Override public final Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); IResource resource = null; if (selection instanceof TreeSelection) { final IAdapterManager adapterManager = Platform.getAdapterManager(); final TreeSelection treeSelection = (TreeSelection) selection; resource = adapterManager.getAdapter(treeSelection.getFirstElement(), IResource.class); } else if (selection instanceof TextSelection) { resource = WorkbenchUtil.getCurrentDocument(); } if (resource != null) { final BeyondCompare bc = new BeyondCompare(); final int resourceType = resource.getType(); if ((resourceType == IResource.FOLDER) || (resourceType == IResource.PROJECT)) { bc.setSavedLeft(resource.getLocation().toString()); bc.setSavedLeftType(BeyondCompareSavedLeft.Directory); bc.writeRegistry(); } else if (resourceType == IResource.FILE) { bc.setSavedLeft(resource.getLocation().toString()); bc.setSavedLeftType(BeyondCompareSavedLeft.File); bc.writeRegistry(); } } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); final Object[] paths = selection.toArray(); final IAdapterManager adapterManager = Platform.getAdapterManager(); final IResource leftResource = adapterManager.getAdapter(paths[0], IResource.class); final IResource rightResource = adapterManager.getAdapter(paths[1], IResource.class); if ((leftResource != null) && (rightResource != null)) { BeyondCompare.compare(leftResource.getLocation().toString(), rightResource.getLocation().toString()); } return null; }
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection != null) { final IAdapterManager adapterManager = Platform.getAdapterManager(); if ((selection != null) && (selection.isEmpty() == false)) { Object receiver = null; // Context menu has been opened in a tree view if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; receiver = structuredSelection.getFirstElement(); } else if (selection instanceof TextSelection) { receiver = WorkbenchUtil.getCurrentDocument(); } final IResource rightResource; rightResource = adapterManager.getAdapter(receiver, IResource.class); if (rightResource != null) { final BeyondCompare bc = new BeyondCompare(); bc.readRegistry(); final String savedLeft = bc.getSavedLeft(); BeyondCompare.compare(savedLeft, rightResource.getLocation().toString()); } } } return null; }
/** * @return The current document of the workbench. */ public static IResource getCurrentDocument() { final IAdapterManager adapterManager = Platform.getAdapterManager(); final IWorkbench wb = PlatformUI.getWorkbench(); final IWorkbenchWindow window = wb.getActiveWorkbenchWindow(); final IWorkbenchPage page = window.getActivePage(); final IEditorPart editor = page.getActiveEditor(); if (editor != null) { final IEditorInput input = editor.getEditorInput(); return adapterManager.getAdapter(input, IResource.class); } return null; }
protected static List<IResource> getSelectedResources(final IStructuredSelection selection) { final IAdapterManager adapterManager = Platform.getAdapterManager(); final List<IResource> selectedResources = new ArrayList<>(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { final IResource selectedResource = (IResource) adapterManager.getAdapter(iterator.next(), IResource.class); if (null != selectedResource) { selectedResources.add(selectedResource); } } return selectedResources; }
private void registerActions( ) { final IActionBars actionBars = getViewSite( ).getActionBars( ); IToolBarManager toolbarManager = actionBars.getToolBarManager( ); exportAction = new ExportSampleReportAction( instance ); toolbarManager.add( exportAction ); toolbarManager.add( new Separator( ) ); Object adapter = null; int status = Platform.getAdapterManager( ).queryAdapter( this, IAction.class.getName( ) ); if ( status == IAdapterManager.LOADED ) { adapter = Platform.getAdapterManager( ).getAdapter( this, IAction.class ); } else if ( status == IAdapterManager.NOT_LOADED ) { // Cause the plug-in loading first adapter = Platform.getAdapterManager( ).loadAdapter( this, IAction.class.getName( ) ); } if ( adapter != null ) { importAction = ( (IOpenSampleReportAction) adapter ); importAction.setMainComposite( instance ); toolbarManager.add( (Action) importAction ); } actionBars.updateActionBars( ); }
public static IAdapterManager getAdapterManager( ) { if ( platform != null ) { return platform.getAdapterManager( ); } return null; }
public void shutdown(IProgressMonitor monitor) throws CoreException { IAdapterManager mgr = Platform.getAdapterManager(); mgr.unregisterAdapters(localResourceAdapterFactory); localResourceAdapterFactory = null; }
@Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; IAdapterManager adapterManager = Platform.getAdapterManager(); adapterManager.registerAdapters(bookmarkAdapterFactory, Bookmark.class); adapterManager.registerAdapters(bookmarkAdapterFactory, BookmarkLink.class); RemoteBookmarksStoreLoader remoteBookmarksStoreLoader = new RemoteBookmarksStoreLoader(); remoteBookmarksStoreManager = new RemoteBookmarksStoreManager(remoteBookmarksStoreLoader); File bookmarksFile = new File(getStateLocation().toFile(), "bookmarks.json"); BookmarksModificationValidator bookmarksModificationValidator = new BookmarksModificationValidator( remoteBookmarksStoreManager); bookmarkDatabase = loadBookmarkDatabase(bookmarksFile, bookmarksModificationValidator); pluginBookmarkTypes = new PluginBookmarkTypes(); bookmarkProblemDescriptors = new BookmarkProblemDescriptors(); bookmarkLabelProvider = new PluginBookmarkLabelProvider(pluginBookmarkTypes); PluginBookmarkMarkerAttributesProvider bookmarkMarkerAttributesProvider = new PluginBookmarkMarkerAttributesProvider( pluginBookmarkTypes); bookmarkPropertiesProvider = new PluginBookmarkPropertiesProvider(pluginBookmarkTypes); bookmarkLocationProvider = new PluginBookmarkLocationProvider(pluginBookmarkTypes); gotoBookmark = new PluginGotoBookmark(pluginBookmarkTypes); bookmarksMarkers = new BookmarksMarkers(bookmarkDatabase, bookmarkMarkerAttributesProvider); importTeamProjectProvider = new ImportTeamProjectProvider(pluginBookmarkTypes); bookmarksMarkers.init(); LocalBookmarksSaver localBookmarksSaver = new LocalBookmarksSaver(bookmarksFile, new BookmarksTreeJsonSerializer(true)); RemoteBookmarksSaver remoteBookmarksSaver = new RemoteBookmarksSaver(remoteBookmarksStoreManager); bookmarksSaver = new BookmarksAutoSaver(bookmarkDatabase, localBookmarksSaver, remoteBookmarksSaver); bookmarksSaver.init(); IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(PLUGIN_ID); File mostVisitedBookmarksFile = new File(getStateLocation().toFile(), "mostVisitedBookmarks.json"); IEventBroker eventBroker = (IEventBroker) getWorkbench().getService(IEventBroker.class); mostVisitedBookmarks = new VisitedBookmarksDatabase(eventBroker, bookmarkDatabase, mostVisitedBookmarksFile); mostVisitedBookmarks.init(); remoteBookmarksTreeChangeEventHandler = new RemoteBookmarksTreeChangeEventHandler(eventBroker, new RefreshRemoteFolderOperation(bookmarkDatabase, remoteBookmarksStoreManager, bookmarksSaver)); remoteBookmarksTreeChangeEventHandler.subscribe(); numberedBookmarks = new NumberedBookmarks((IEclipsePreferences) preferences.node("numberedBookmarks"), eventBroker); numberedBookmarks.init(); File recentBookmarksFile = new File(getStateLocation().toFile(), "recentBookmarks.json"); recentBookmarks = new RecentBookmarksDatabase(eventBroker, bookmarkDatabase, recentBookmarksFile, Duration.ofDays(5)); recentBookmarks.init(); File bookmarkProblemsFile = new File(getStateLocation().toFile(), "bookmarkProblems.json"); bookmarkProblems = new BookmarkProblemsDatabase(eventBroker, bookmarkDatabase, bookmarkProblemDescriptors, bookmarkProblemsFile); bookmarkProblems.init(); File storeFile = new File(getStateLocation().toFile(), "placeholders.json"); pathPlaceholdersStore = new PathPlaceholdersStore(eventBroker, storeFile); pathPlaceholdersStore.init(); if (pathPlaceholdersStore.get(PLACEHOLDER_HOME_NAME) == null) { IPath userHome = getUserHome(); if (userHome != null) { pathPlaceholdersStore.add(new PathPlaceholder(PLACEHOLDER_HOME_NAME, userHome)); } } INewBookmarkPositionProvider newBookmarkPositionProvider = new NewBookmarkPositionProvider(bookmarkDatabase); bookmarksService = new BookmarksService(bookmarkDatabase, bookmarkPropertiesProvider, newBookmarkPositionProvider, remoteBookmarksStoreManager, bookmarksSaver, bookmarkLocationProvider, gotoBookmark, numberedBookmarks, pluginBookmarkTypes, bookmarksMarkers, pathPlaceholdersStore, bookmarkProblems, eventBroker); CheckBookmarkPropertiesOperation checkBookmarkPropertiesOperation = new CheckBookmarkPropertiesOperation( bookmarkDatabase, remoteBookmarksStoreManager, pluginBookmarkTypes, bookmarkPropertiesProvider, new PathPlaceholderResolver(pathPlaceholdersStore), bookmarkProblems); bookmarkProblemsAutoUpdater = new BookmarkProblemsAutoUpdater(eventBroker, bookmarkDatabase, bookmarkProblems, new PathPropertiesProvider(pluginBookmarkTypes), checkBookmarkPropertiesOperation); bookmarkProblemsAutoUpdater.init(); }
@Override protected final IContributionItem[] getContributionItems() { // By default, return an empty list (if context menu entry must not be // shown) Boolean showEntry = false; IContributionItem[] items = new IContributionItem[] {}; final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { final ISelection selection = window.getSelectionService().getSelection(); if ((selection != null) && (selection.isEmpty() == false)) { Object receiver = null; // Context menu has been opened in a tree view if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; receiver = structuredSelection.getFirstElement(); } else if (selection instanceof TextSelection) { receiver = WorkbenchUtil.getCurrentDocument(); } if (receiver != null) { final BeyondCompareSavedLeft savedLeftType = bc.getSavedLeftType(); final IAdapterManager adapterManager = Platform.getAdapterManager(); if (adapterManager != null) { int resourceType = IResource.NONE; final IResource resource = adapterManager.getAdapter(receiver, IResource.class); if (resource != null) { resourceType = resource.getType(); } if (((resourceType == IResource.PROJECT) || (resourceType == IResource.FOLDER)) && (savedLeftType == BeyondCompareSavedLeft.Directory)) { showEntry = true; } else if ((resourceType == IResource.FILE) && (savedLeftType == BeyondCompareSavedLeft.File)) { showEntry = true; } else { showEntry = false; } if (showEntry) { final String savedLeft = bc.getSavedLeft(); if (savedLeft != null) { final CommandContributionItemParameter parameter = new CommandContributionItemParameter(this.currentServiceLocator, null, "ContextQuickie.commands.compareToRight", 0); final String filename = new File(savedLeft).getName(); parameter.label = "Compare to " + filename; parameter.icon = contextquickie.Activator.getImageDescriptor("icons/BeyondCompare/Compare.png"); items = new IContributionItem[] { new CommandContributionItem(parameter) }; } } } } } } return items; }
@Override public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) { boolean returnValue = false; final TreeSelection selection = (TreeSelection) receiver; final Object[] paths = selection.toArray(); final IAdapterManager adapterManager = Platform.getAdapterManager(); if (adapterManager != null) { int leftType = IResource.NONE; final IResource left = adapterManager.getAdapter(paths[0], IResource.class); if (left != null) { leftType = left.getType(); } int rightType = IResource.NONE; final IResource right = adapterManager.getAdapter(paths[1], IResource.class); if (right != null) { rightType = right.getType(); } if ((leftType == IResource.FILE) && (rightType == IResource.FILE)) { returnValue = true; } else if ((leftType == IResource.FOLDER) && (rightType == IResource.FOLDER)) { returnValue = true; } else if ((leftType == IResource.FOLDER) && (rightType == IResource.PROJECT)) { returnValue = true; } else if ((leftType == IResource.PROJECT) && (rightType == IResource.FOLDER)) { returnValue = true; } else if ((leftType == IResource.PROJECT) && (rightType == IResource.PROJECT)) { returnValue = true; } } return returnValue; }
public IAdapterManager getAdapterManager() { return AdapterManager.getDefault(); }
public static <T> T getAdapter( Object adaptable, Class<T> adapterClass ) { IAdapterManager adapterManager = org.eclipse.birt.core.framework.Platform.getAdapterManager( ); return adapterClass.cast( adapterManager.loadAdapter( adaptable, adapterClass.getName( ) ) ); }
public IAdapterManager getAdapterManager( ) { return AdapterManager.getDefault( ); }
public IAdapterManager getAdapterManager( ) { return Platform.getAdapterManager( ); }
/** * Gets adapter from extension point. * * @param <T> * @param adaptable * @param type * @return adapter class * @since 2.5.1 */ public static <T> T getAdapter( Object adaptable, Class<T> type ) { // use BIRT platform as the Eclipse platform may throws exception if the // OSGi is not started IAdapterManager adapterManager = org.eclipse.birt.core.framework.Platform.getAdapterManager( ); return type.cast( adapterManager.loadAdapter( adaptable, type.getName( ) ) ); }
IAdapterManager getAdapterManager( );