Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Registered EPackage Dialog #451

Open
chqu1012 opened this issue Jun 27, 2019 · 1 comment
Open

Open Registered EPackage Dialog #451

chqu1012 opened this issue Jun 27, 2019 · 1 comment

Comments

@chqu1012
Copy link
Owner

Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
RegisteredPackageDialog registeredPackageDialog = new RegisteredPackageDialog(shell) {
@OverRide
protected void setListElements(Object[] elements) {
if (elements == null)
return;
List pckUris = new LinkedList();
for (Object element : elements) {
if (!getProjectInfo().getFilterSystemEPackages() || !ePackageUriFilter.apply(element.toString()))
pckUris.add(element.toString());
}
super.setListElements(pckUris.toArray());
}
};
registeredPackageDialog.setMultipleSelection(false);
registeredPackageDialog.open();
Object[] result = registeredPackageDialog.getResult();
if (result != null) {
List<?> nsURIs = Arrays.asList(result);
setNsURIs(nsURIs, txtUri, registeredPackageDialog.isDevelopmentTimeVersion(), false);
}

@chqu1012 chqu1012 created this issue from a note in EMF.edit to viewers Integration (In progress) Jun 27, 2019
@chqu1012
Copy link
Owner Author

Another solution: https://www.programcreek.com/java-api-examples/?code=abelgomez/emf.utils/emf.utils-master/io.github.abelgomez.emf.utils.ui/src/io/github/abelgomez/emf/utils/ui/views/PackageRegistryView.java

	registerAction = new Action() {
		public void run() {
			ResourceDialog dialog = new EcoreResourceDialog(shell, "Select an Ecore Resource", SWT.OPEN | SWT.MULTI);
			if (dialog.open() == ResourceDialog.OK) {
				for (URI uri : dialog.getURIs()) {
					try {
						EPackage ePackage = EMFUtilsPlugin.getDefault().getRegistryManager().loadEPackage(uri);
						EMFUtilsPlugin.getDefault().getRegistryManager().registerEPackage(ePackage, true);
					} catch (Exception e) {
						EMFUtilsUiPlugin.getDefault().getLog().log(ExceptionStatus.createExceptionStatus(e));	
					}
				}
		 	}
		}
	};
	registerAction.setText("Register");
	registerAction.setToolTipText("Adds a new EPackage to the EMF EPackages registry");
	registerAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
			getImageDescriptor(ISharedImages.IMG_OBJ_ADD));

	unregisterAction = new Action() {
		public void run() {
			ISelection selection = viewer.getSelection();
			if (!selection.isEmpty()) {
				Iterator<?> it = ((IStructuredSelection) selection).iterator();
				while (it.hasNext()) {
					Entry<?, ?> obj = (Entry<?, ?>) it.next();
					try {
						URI nsUri = URI.createURI((String) obj.getKey());
						EPackage ePackage = EMFUtilsPlugin.getDefault().getRegistryManager().getEPackage(nsUri);
						EMFUtilsPlugin.getDefault().getRegistryManager().unregisterEPackage(ePackage);
					} catch (Exception e) {
						EMFUtilsUiPlugin.getDefault().getLog().log(ExceptionStatus.createExceptionStatus(e));	
					}
				}
			}
		}
	};
	unregisterAction.setText("Unregister");
	unregisterAction.setToolTipText("Deletes the entry from the EMF EPackages registry");
	unregisterAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
			getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

1 participant