Author: dgeraskov
Date: 2009-10-13 09:10:53 -0400 (Tue, 13 Oct 2009)
New Revision: 18065
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/AddRemoveTableComposite.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage2.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4872
updated ui
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java 2009-10-13
13:00:09 UTC (rev 18064)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.java 2009-10-13
13:10:53 UTC (rev 18065)
@@ -35,6 +35,14 @@
public static String ResolveAmbiguous_column_Owner;
public static String ResolveAmbiguous_empty;
public static String ResolveAmbiguous_message;
+ public static String AddRemoveTableComposite_add_class;
+ public static String AddRemoveTableComposite_add_package;
+ public static String AddRemoveTableComposite_java_types_title;
+ public static String AddRemoveTableComposite_java_packages_title;
+ public static String AddRemoveTableComposite_java_select_types;
+ public static String AddRemoveTableComposite_java_select_packages;
+ public static String NewHibernateMappingElementsSelectionPage2_description;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, JdtUiMessages.class);
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties 2009-10-13
13:00:09 UTC (rev 18064)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/JdtUiMessages.properties 2009-10-13
13:10:53 UTC (rev 18065)
@@ -39,3 +39,10 @@
ResolveAmbiguous_column_Owner=Owner
ResolveAmbiguous_empty=<empty>
ResolveAmbiguous_message=Edit entities relations.
+AddRemoveTableComposite_add_class=Add Class...
+AddRemoveTableComposite_add_package=Add Package...
+AddRemoveTableComposite_java_types_title=Java Types
+AddRemoveTableComposite_java_packages_title=Packages
+AddRemoveTableComposite_java_select_types=Select types to be mapped
+AddRemoveTableComposite_java_select_packages=Select packages to search for java types
+NewHibernateMappingElementsSelectionPage2_description=Add classes and packages to create
mapping files for
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/AddRemoveTableComposite.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/AddRemoveTableComposite.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/AddRemoveTableComposite.java 2009-10-13
13:10:53 UTC (rev 18065)
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.hibernate.eclipse.jdt.ui.wizards;
+
+import org.eclipse.jdt.core.IJavaProject;
+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.core.JavaModelManager;
+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.ArrayContentProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.hibernate.eclipse.console.wizards.UpDownListComposite;
+import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+@SuppressWarnings("restriction")
+public class AddRemoveTableComposite extends UpDownListComposite {
+
+ public AddRemoveTableComposite(Composite parent, int style) {
+ super(parent, style, "", //$NON-NLS-1$
+ false, new JavaElementLabelProvider(),
+ ArrayContentProvider.getInstance());
+ setUpDownVisible(false);
+ }
+
+ @Override
+ protected String[] getAddButtonLabels() {
+ return new String[] { JdtUiMessages.AddRemoveTableComposite_add_class,
+ JdtUiMessages.AddRemoveTableComposite_add_package};
+ }
+
+ protected void createColumns(Table table) {
+ TableColumn column = new TableColumn(table, SWT.NULL);
+ column.setWidth(350);
+ }
+
+ protected Object[] handleAdd(int i) {
+
+ SelectionDialog dialog= null;
+ try {
+ IJavaProject[] projects =
JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
+
+ int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(projects, includeMask);
+
+ if (i == 0){
+ dialog=
+ JavaUI.createTypeDialog(
+ getShell(),
+ PlatformUI.getWorkbench().getProgressService(),
+ scope,
+ IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES,
+ true);
+ dialog.setTitle(JdtUiMessages.AddRemoveTableComposite_java_types_title);
+ dialog.setMessage(JdtUiMessages.AddRemoveTableComposite_java_select_types);
+ } else if (i == 1){
+ dialog=
+ JavaUI.createPackageDialog(
+ getShell(),
+ PlatformUI.getWorkbench().getProgressService(),
+ scope,
+ true,
+ true,
+ null);
+ dialog.setTitle(JdtUiMessages.AddRemoveTableComposite_java_packages_title);
+ dialog.setMessage(JdtUiMessages.AddRemoveTableComposite_java_select_packages);
+ } else {
+ return null;
+ }
+
+
+ if (dialog.open() == IDialogConstants.CANCEL_ID)
+ return null;
+
+ return dialog.getResult();
+ } catch (JavaModelException jme) {
+ return null;
+ }
+ }
+
+
+
+}
+
Property changes on:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/AddRemoveTableComposite.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage2.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage2.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage2.java 2009-10-13
13:10:53 UTC (rev 18065)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.hibernate.eclipse.jdt.ui.wizards;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TableItem;
+import org.hibernate.eclipse.jdt.ui.internal.JdtUiMessages;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class NewHibernateMappingElementsSelectionPage2 extends WizardPage {
+
+ AddRemoveTableComposite addRemoveTableComposite;
+
+ private IStructuredSelection selection;
+
+ public NewHibernateMappingElementsSelectionPage2(String pageName, IStructuredSelection
selection) {
+ super(pageName);
+ this.selection = selection;
+ setDescription(JdtUiMessages.NewHibernateMappingElementsSelectionPage2_description);
+ }
+
+ public void createControl(Composite parent) {
+ addRemoveTableComposite = new AddRemoveTableComposite(parent, SWT.NONE);
+ addRemoveTableComposite.getTableViewer().setInput(selection.toArray());
+ setControl(addRemoveTableComposite);
+ }
+
+ public IStructuredSelection getSelection(){
+ TableItem[] items = addRemoveTableComposite.getTableViewer().getTable().getItems();
+ Object[] data = new Object[items.length];
+ for (int i = 0; i < items.length; i++) {
+ data[i] = items[i].getData();
+ }
+ return new StructuredSelection(data);
+ }
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage2.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java 2009-10-13
13:00:09 UTC (rev 18064)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java 2009-10-13
13:10:53 UTC (rev 18065)
@@ -164,6 +164,7 @@
private class TableContentProvider implements IStructuredContentProvider {
+ @SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Map) {
List<TableLine> result = new ArrayList<TableLine>();
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2009-10-13
13:00:09 UTC (rev 18064)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2009-10-13
13:10:53 UTC (rev 18065)
@@ -11,6 +11,7 @@
package org.hibernate.eclipse.jdt.ui.wizards;
import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -27,6 +28,8 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IParent;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.JavaElementInfo;
@@ -37,6 +40,7 @@
import org.eclipse.jface.dialogs.PageChangingEvent;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
@@ -67,24 +71,31 @@
private Map<IJavaProject, Collection<EntityInfo>> project_infos = new
HashMap<IJavaProject, Collection<EntityInfo>>();
- private IStructuredSelection selection;
+ private IStructuredSelection selection;
+
+ private NewHibernateMappingElementsSelectionPage2 page0 = null;
- private NewHibernateMappingElementsSelectionPage page1 = null;
+ //private NewHibernateMappingElementsSelectionPage page1 = null;
private NewHibernateMappingFilePage page2 = null;
public NewHibernateMappingFileWizard(){
setDefaultPageImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.NEW_WIZARD)
);
setNeedsProgressMonitor(true);
+ setWindowTitle(HibernateConsoleMessages.NewHibernateMappingFileWizard_create_hibernate_xml_mapping_file);
}
@Override
public void addPages() {
super.addPages();
- page1 = new NewHibernateMappingElementsSelectionPage(selection);
- page1.setTitle(
HibernateConsoleMessages.NewHibernateMappingFileWizard_create_hibernate_xml_mapping_file
);
- page1.setDescription(
HibernateConsoleMessages.NewHibernateMappingFileWizard_create_new_xml_mapping_file );
- addPage(page1);
+
+ page0 = new
NewHibernateMappingElementsSelectionPage2(HibernateConsoleMessages.NewHibernateMappingFileWizard_create_hibernate_xml_mapping_file,
selection);
+ addPage(page0);
+
+ //page1 = new NewHibernateMappingElementsSelectionPage(selection);
+ //page1.setTitle(
HibernateConsoleMessages.NewHibernateMappingFileWizard_create_hibernate_xml_mapping_file
);
+ //page1.setDescription(
HibernateConsoleMessages.NewHibernateMappingFileWizard_create_new_xml_mapping_file );
+ //addPage(page1);
page2 = new NewHibernateMappingFilePage();
addPage(page2);
}
@@ -102,13 +113,63 @@
public void handlePageChanging(PageChangingEvent event) {
if (event.getTargetPage() == page2){
- updateCompilationUnits();
- page2.setInput(project_infos);
+ updateCompilationUnits();
+ page2.setInput(project_infos);
}
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
- this.selection = selection;
+ Set<IJavaElement> filteredElements = new HashSet<IJavaElement>();
+ Object[] elements = selection.toArray();
+ for (int i = 0; i < elements.length; i++) {
+ if (elements[i] instanceof JavaProject) {
+ JavaProject project = (JavaProject) elements[i];
+ try {
+ IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
+ for (int j = 0; j < roots.length; j++) {
+ if (!roots[j].isArchive()){
+ IJavaElement[] rootChildren = roots[j].getChildren();
+ for (int k = 0; k < rootChildren.length; k++) {
+ if (rootChildren[k] instanceof IParent &&
((IParent)rootChildren[k]).hasChildren()){
+ filteredElements.add(rootChildren[k]);
+ }
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ } else if (elements[i] instanceof IPackageFragmentRoot) {
+ IPackageFragmentRoot root = (IPackageFragmentRoot)elements[i];
+ if (!root.isArchive()){
+ try {
+ filteredElements.addAll(Arrays.asList((root.getChildren())));
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ }
+ } else if (elements[i] instanceof ICompilationUnit) {
+ ICompilationUnit cu = (ICompilationUnit)elements[i];
+ IType[] types;
+ try {
+ types = cu.getTypes();
+ //remove java extension.
+ String typeName = cu.getElementName().substring(0, cu.getElementName().length() -
5);
+ for (int j = 0; j < types.length; j++) {
+ if (types[j].getElementName().equals(typeName)){
+ filteredElements.add(types[j]);
+ break;
+ }
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+
+ } else if (elements[i] instanceof IJavaElement) {
+ filteredElements.add((IJavaElement) elements[i]);
+ }
+ }
+ this.selection = new StructuredSelection(filteredElements.toArray());
}
@Override
@@ -227,11 +288,11 @@
protected void updateCompilationUnits(){
- Assert.isNotNull(page1.getSelection(),
HibernateConsoleMessages.NewHibernateMappingFileWizard_selection_cant_be_empty);
- if ((selectionCU == null) || !page1.getSelection().equals(selection)) {
+ Assert.isNotNull(page0.getSelection(),
HibernateConsoleMessages.NewHibernateMappingFileWizard_selection_cant_be_empty);
+ if ((selectionCU == null) || !page0.getSelection().equals(selection)) {
selectionCU = new HashSet<ICompilationUnit>();
project_infos.clear();
- selection = page1.getSelection();
+ selection = page0.getSelection();
try {
getContainer().run(false, false, new IRunnableWithProgress() {