Author: dgeraskov
Date: 2012-08-24 08:56:23 -0400 (Fri, 24 Aug 2012)
New Revision: 43219
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePersistenceUnitClassesComposite.java
Log:
Mode package selection dialog to DialogSelectionHelper class
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java 2012-08-24
12:54:41 UTC (rev 43218)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/DialogSelectionHelper.java 2012-08-24
12:56:23 UTC (rev 43219)
@@ -23,21 +23,28 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.debug.internal.ui.stringsubstitution.StringVariableLabelProvider;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.internal.ui.dialogs.PackageSelectionDialog;
+import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.IFilter;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.dialogs.FilteredList;
import org.eclipse.ui.dialogs.SelectionDialog;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
@@ -130,5 +137,49 @@
}
return null;
}
+
+ public static IPackageFragment choosePackage(Shell shell, IJavaElement[] javaProjects,
final IFilter filter, String title, String message){
+ BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext();
+ IJavaSearchScope scope = SearchEngine
+ .createJavaSearchScope(javaProjects, IJavaSearchScope.SOURCES
+ | IJavaSearchScope.REFERENCED_PROJECTS);
+ PackageSelectionDialog packageSelectionDialog = new PackageSelectionDialog(
+ shell, context,
+ PackageSelectionDialog.F_HIDE_DEFAULT_PACKAGE
+ | PackageSelectionDialog.F_HIDE_EMPTY_INNER, scope) {
+
+ @Override
+ protected FilteredList createFilteredList(Composite parent) {
+ FilteredList list = super.createFilteredList(parent);
+ if (filter != null){
+ list.setFilterMatcher(new FilteredList.FilterMatcher() {
+
+ @Override
+ public void setFilter(String pattern, boolean ignoreCase,
+ boolean ignoreWildCards) {
+ }
+
+ @Override
+ public boolean match(Object element) {
+ return filter.select(element);
+ }
+ }
+ );
+ }
+ return list;
+ }
+ };
+
+ packageSelectionDialog.setTitle(title);
+ packageSelectionDialog.setMessage(message);
+
+ if (packageSelectionDialog.open() == Window.OK) {
+ return (IPackageFragment) packageSelectionDialog.getResult()[0];
+ }
+
+ return null;
+
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePersistenceUnitClassesComposite.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePersistenceUnitClassesComposite.java 2012-08-24
12:54:41 UTC (rev 43218)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePersistenceUnitClassesComposite.java 2012-08-24
12:56:23 UTC (rev 43219)
@@ -22,10 +22,9 @@
import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
-import org.eclipse.jdt.internal.ui.dialogs.PackageSelectionDialog;
-import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.viewers.IFilter;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
@@ -52,9 +51,9 @@
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.FilteredList;
import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.ui.progress.IProgressService;
+import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
import org.jboss.tools.hibernate.jpt.core.internal.context.persistence.PackageInfoRef;
@@ -279,51 +278,25 @@
}
private IPackageFragment choosePackage() {
- IJavaElement[] elements = new IJavaElement[] { getJavaProject() };
- BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext();
- IJavaSearchScope scope = SearchEngine
- .createJavaSearchScope(elements, IJavaSearchScope.SOURCES
- | IJavaSearchScope.REFERENCED_PROJECTS);
+ return DialogSelectionHelper.choosePackage(getShell(),
+ new IJavaProject[]{getJavaProject()},
+ createPackageFilter(),
+ Messages.HibernatePersistenceUnitClassesComposite_PackageSelectionDialog_title,
+ JptCommonUiMessages.ClassChooserPane_dialogMessage);
+ }
+
+ protected IFilter createPackageFilter(){
+ return new IFilter() {
+
+ public boolean select(Object element) {
+ if (element instanceof PackageFragment) {
+ PackageFragment pf = (PackageFragment) element;
+ return pf.getCompilationUnit(Hibernate.PACKAGE_INFO_JAVA).exists();
- PackageSelectionDialog packageSelectionDialog = new PackageSelectionDialog(
- getShell(), context,
- PackageSelectionDialog.F_HIDE_DEFAULT_PACKAGE
- | PackageSelectionDialog.F_HIDE_EMPTY_INNER, scope) {
-
- @Override
- protected FilteredList createFilteredList(Composite parent) {
- FilteredList list = super.createFilteredList(parent);
- //filter out packages without package-ifo.java
- list.setFilterMatcher(new FilteredList.FilterMatcher() {
-
- @Override
- public void setFilter(String pattern, boolean ignoreCase,
- boolean ignoreWildCards) {
- }
-
- @Override
- public boolean match(Object element) {
- if (element instanceof PackageFragment) {
- PackageFragment pf = (PackageFragment) element;
- return pf.getCompilationUnit(Hibernate.PACKAGE_INFO_JAVA).exists();
-
- }
- return false;
- }
- });
- return list;
+ }
+ return false;
}
};
-
- packageSelectionDialog.setTitle(Messages.HibernatePersistenceUnitClassesComposite_PackageSelectionDialog_title);
- packageSelectionDialog
- .setMessage(JptCommonUiMessages.ClassChooserPane_dialogMessage);
-
- if (packageSelectionDialog.open() == Window.OK) {
- return (IPackageFragment) packageSelectionDialog.getResult()[0];
- }
-
- return null;
}
/*
Show replies by date