Author: dgeraskov
Date: 2009-05-15 11:07:03 -0400 (Fri, 15 May 2009)
New Revision: 15296
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage.java
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/NewHibernateMappingFileWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3457
Raw code - without validation Next and Finish,
without wizard's descriptions...
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage.java 2009-05-15
15:07:03 UTC (rev 15296)
@@ -0,0 +1,133 @@
+package org.hibernate.eclipse.jdt.ui.wizards;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IParent;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
+import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+
+public class NewHibernateMappingElementsSelectionPage extends WizardPage {
+
+ // the current selection
+ private IStructuredSelection fCurrentSelection;
+
+ private TreeViewer fViewer;
+
+ private boolean fAllowMultiple = true;
+
+ private int fWidth = 50;
+
+ private int fHeight = 18;
+
+ public NewHibernateMappingElementsSelectionPage(IStructuredSelection selection) {
+ super("", "", null);
+ fCurrentSelection = selection;
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ composite.setLayout(new GridLayout());
+ createTreeViewer(composite);
+
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.widthHint = convertWidthInCharsToPixels(fWidth);
+ data.heightHint = convertHeightInCharsToPixels(fHeight);
+
+ Tree treeWidget = fViewer.getTree();
+ treeWidget.setLayoutData(data);
+ setControl(composite);
+ }
+
+ protected TreeViewer createTreeViewer(Composite composite) {
+ int style = SWT.BORDER | (fAllowMultiple ? SWT.MULTI : SWT.SINGLE);
+ fViewer = new TreeViewer(new Tree(composite, style));
+ fViewer.setContentProvider(new StandardJavaElementContentProvider());
+ fViewer.setLabelProvider(new JavaElementLabelProvider());
+ fViewer.setFilters(getFilters());
+ fViewer.addSelectionChangedListener(getSelectionChangedListener());
+ fViewer.setInput(getInput());
+ fViewer.setSelection(fCurrentSelection, true);
+ return fViewer;
+ }
+
+ protected ViewerFilter[] getFilters(){
+ return new ViewerFilter[] { new ViewerFilter() {
+
+ public boolean hasCompilationUnits(IParent parent){
+ IJavaElement[] elements;
+ try {
+ elements = parent.getChildren();
+ for (int i = 0; i < elements.length; i++) {
+ if (elements[i].getElementType() == IJavaElement.COMPILATION_UNIT){
+ return true;
+ } else if (elements[i] instanceof IParent
+ && !(elements[i] instanceof JarPackageFragmentRoot)){
+ if (hasCompilationUnits((IParent)elements[i])) {
+ return true;
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ return false;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement,
+ Object element) {
+ if (element instanceof JarPackageFragmentRoot) {
+ return false;
+ } else if (element instanceof ICompilationUnit) {
+ return true;
+ } else if (element instanceof IParent) {
+ return hasCompilationUnits((IParent)element);
+ } else {
+ return false;
+ }
+ }
+
+ } };
+ }
+
+ protected Object getInput(){
+ return JavaCore.create( ResourcesPlugin.getWorkspace().getRoot() );
+ }
+
+ public IStructuredSelection getSelection(){
+ return fCurrentSelection;
+ }
+
+ protected ISelectionChangedListener getSelectionChangedListener() {
+ return new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ fCurrentSelection = (IStructuredSelection) event.getSelection();
+ updateStatus();
+ }
+ };
+ }
+
+ public void setAllowMultiple(boolean isAllowMultiple){
+ fAllowMultiple = isAllowMultiple;
+ }
+
+ protected void updateStatus() {
+ // TODO Auto-generated method stub
+ }
+}
Property changes on:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingElementsSelectionPage.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-05-15
15:05:25 UTC (rev 15295)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFilePage.java 2009-05-15
15:07:03 UTC (rev 15296)
@@ -1,13 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2007-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
- ******************************************************************************/
+ * Copyright (c) 2007-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 java.util.ArrayList;
@@ -33,6 +33,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
@@ -46,19 +47,16 @@
*
*/
public class NewHibernateMappingFilePage extends WizardPage {
-
+
private TableViewer viewer;
-
- private Map<IJavaProject, Collection<EntityInfo>> project_infos;
/**
* @param pageName
*/
- protected NewHibernateMappingFilePage(Map<IJavaProject,
Collection<EntityInfo>> project_infos) {
+ protected NewHibernateMappingFilePage() {
super("");
setTitle(HibernateConsoleMessages.NewHibernateMappingFilePage_hibernate_xml_mapping_file);
- setDescription(HibernateConsoleMessages.NewHibernateMappingFilePage_this_wizard_creates);
- this.project_infos = project_infos;
+ setDescription(HibernateConsoleMessages.NewHibernateMappingFilePage_this_wizard_creates);
}
public void createControl(Composite parent) {
@@ -69,100 +67,104 @@
sc.pack(false);
Composite container = new Composite(sc, SWT.NULL);
- sc.setContent(container);
+ sc.setContent(container);
- FillLayout layout = new FillLayout();
+ Layout layout = new FillLayout();
container.setLayout(layout);
-
+
Table table = new Table(container, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL |
SWT.V_SCROLL | SWT.FULL_SELECTION );
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.pack(false);
createTableColumns(table);
- viewer = createTableFilterViewer(table);
- viewer.setInput(project_infos);
-
+ viewer = createTableViewer(table);
+ viewer.setInput(null);
+
sc.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));
- setControl(sc);
+ setControl(container);
}
-
+
private void createTableColumns(Table table){
int coulmnIndex = 0;
TableColumn column = new TableColumn(table, SWT.CENTER, coulmnIndex++);
column.setText("!");
column.setWidth(20);
- column.setResizable(false);
-
- if (project_infos.keySet().size() > 1){
- column = new TableColumn(table, SWT.LEFT, coulmnIndex++);
- column.setText("Project name");
- column.setWidth(120);
- }
-
+ column.setResizable(false);
+
+ //if (project_infos.keySet().size() > 1){
column = new TableColumn(table, SWT.LEFT, coulmnIndex++);
+ column.setText("Project name");
+ column.setWidth(120);
+ //}
+
+ column = new TableColumn(table, SWT.LEFT, coulmnIndex++);
column.setText("Class name");
column.setWidth(150);
-
+
column = new TableColumn(table, SWT.LEFT, coulmnIndex++);
column.setText("File name");
column.setWidth(150);
}
-
- private TableViewer createTableFilterViewer(Table table) {
+
+ private TableViewer createTableViewer(Table table) {
TableViewer result = new TableViewer( table );
result.setUseHashlookup( true );
- if (project_infos.keySet().size() > 1){
- result.setColumnProperties( new String[] {"create", "project",
//$NON-NLS-1$//$NON-NLS-2$
- "class", "file",} ); //$NON-NLS-1$ //$NON-NLS-2$
- } else {
+ //if (project_infos.keySet().size() > 1){
+ result.setColumnProperties( new String[] {"create", "project",
//$NON-NLS-1$//$NON-NLS-2$
+ "class", "file",} ); //$NON-NLS-1$ //$NON-NLS-2$
+ /*} else {
result.setColumnProperties( new String[] {"create", //$NON-NLS-1$
"class", "file",} ); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
+ }*/
CellEditor[] editors = new CellEditor[result.getColumnProperties().length];
editors[0] = new CheckboxCellEditor( result.getTable() );
editors[1] = new TextCellEditor( result.getTable() );
editors[2] = new TextCellEditor( result.getTable() );
- if (project_infos.keySet().size() > 1){
- editors[3] = new TextCellEditor( result.getTable() );
- }
+ //if (project_infos.keySet().size() > 1){
+ editors[3] = new TextCellEditor( result.getTable() );
+ //}
+
result.setCellEditors( editors );
result.setCellModifier( new TableCellModifier(result) );
result.setLabelProvider(new TableLableProvider(result));
result.setContentProvider( new TableContentProvider() );
return result;
}
-
+
+ public void setInput(Map<IJavaProject, Collection<EntityInfo>>
project_infos){
+ viewer.setInput(project_infos);
+ }
+
private class TableLine {
-
+
public String projectName;
-
+
public String className;
-
+
public String fileName;
-
+
public Boolean isCreate = true;
-
+
public TableLine(String projectName, String className){
this(projectName, className, className + ".hbm.xml",true);
}
-
+
public TableLine(String projectName, String className, String fileName, boolean
isCreate){
this.projectName = projectName;
this.className = className;
this.fileName = fileName;
this.isCreate = isCreate;
}
-
+
}
-
+
private class TableContentProvider implements IStructuredContentProvider {
- public Object[] getElements(Object inputElement) {
+ public Object[] getElements(Object inputElement) {
if (inputElement instanceof Map) {
- List<TableLine> result = new ArrayList<TableLine>();
+ List<TableLine> result = new ArrayList<TableLine>();
Map<IJavaProject, Collection<EntityInfo>> configs = (Map<IJavaProject,
Collection<EntityInfo>>)inputElement;
for (Entry<IJavaProject, Collection<EntityInfo>> entry :
configs.entrySet()) {
Iterator<EntityInfo> iter = entry.getValue().iterator();
@@ -170,35 +172,32 @@
EntityInfo ei = iter.next();
result.add(new TableLine(entry.getKey().getProject().getName(), ei.getName()));
}
- }
+ }
return result.toArray();
}
return new Object[0];
}
- public void dispose() { }
+ public void dispose() {}
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // TODO Auto-generated method stub
-
- }
-
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { }
+
}
-
+
private class TableLableProvider extends LabelProvider implements ITableLabelProvider
{
-
+
private final TableViewer tv;
public TableLableProvider(TableViewer tv) {
this.tv = tv;
}
-
+
public Image getColumnImage(Object element, int columnIndex) {
String property = (String) tv.getColumnProperties()[columnIndex];
if("create".equals(property)) {
TableLine tl = (TableLine) element;
String key = tl.isCreate ? null : ImageConstants.CLOSE ; // TODO: find a better
image
- return EclipseImages.getImage(key);
+ return EclipseImages.getImage(key);
}
return null;
}
@@ -206,19 +205,21 @@
public String getColumnText(Object element, int columnIndex) {
String property = (String) tv.getColumnProperties()[columnIndex];
TableLine tl = (TableLine) element;
-
+
if ("class".equals(property)){
return tl.className;
} else if ("project".equals(property)){
return tl.projectName;
} else if ("file".equals(property)){
return tl.fileName;
- } else return "";
- }
+ } else {
+ return "";
+ }
+ }
}
-
+
private class TableCellModifier implements ICellModifier {
-
+
private final TableViewer tv;
public TableCellModifier(TableViewer tv) {
@@ -253,8 +254,8 @@
} else if ("create".equals(property)){
tl.isCreate = (Boolean)value;
}
-
+
tv.update(new Object[] { tl }, new String[] { property });
- }
+ }
}
}
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-05-15
15:05:25 UTC (rev 15295)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/wizards/NewHibernateMappingFileWizard.java 2009-05-15
15:07:03 UTC (rev 15296)
@@ -1,16 +1,16 @@
/*******************************************************************************
- * Copyright (c) 2007-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
- ******************************************************************************/
+ * Copyright (c) 2007-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 java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -19,35 +19,32 @@
import java.util.Set;
import java.util.Map.Entry;
-import org.eclipse.core.internal.filebuffers.SynchronizableDocument;
import org.eclipse.core.internal.resources.File;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTParser;
-import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.JavaElementInfo;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.dialogs.IPageChangingListener;
+import org.eclipse.jface.dialogs.PageChangingEvent;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ImageConstants;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.EclipseImages;
import org.hibernate.eclipse.jdt.ui.internal.jpa.collect.AllEntitiesInfoCollector;
@@ -60,32 +57,81 @@
* @author Dmitry Geraskov
*
*/
-public class NewHibernateMappingFileWizard extends Wizard implements INewWizard {
-
+public class NewHibernateMappingFileWizard extends Wizard implements INewWizard,
IPageChangingListener{
+
/**
* Selected compilation units for startup processing,
* result of processing selection
*/
private Set<ICompilationUnit> selectionCU = new
HashSet<ICompilationUnit>();
-
+
private Map<IJavaProject, Collection<EntityInfo>> project_infos = new
HashMap<IJavaProject, Collection<EntityInfo>>();
-
+ private IStructuredSelection selection;
+
+ private NewHibernateMappingFilePage page2 = null;
+
+ private NewHibernateMappingElementsSelectionPage page1 = null;
+
public NewHibernateMappingFileWizard(){
setDefaultPageImageDescriptor(EclipseImages.getImageDescriptor(ImageConstants.NEW_WIZARD)
);
+ setNeedsProgressMonitor(true);
}
-
+
@Override
public void addPages() {
super.addPages();
- addPage(new NewHibernateMappingFilePage(project_infos));
+ 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);
+ if (getContainer() instanceof WizardDialog) {
+ ((WizardDialog) getContainer()).addPageChangingListener(this);
+ } else {
+ throw new IllegalArgumentException("Must use WizardDialog implementation as
WizardContainer");
+ }
}
-
+
+ public void handlePageChanging(PageChangingEvent event) {
+ if (event.getTargetPage() == page2){
+ selection = page1.getSelection();
+ try {
+ getContainer().run(false, false, new IRunnableWithProgress(){
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+ monitor.beginTask("Find dependent compilation units", selection.size() +
1);
+ Iterator it = selection.iterator();
+ int done = 1;
+ while (it.hasNext()) {
+ Object obj = it.next();
+ processJavaElements(obj);
+ monitor.worked(done++);
+ Thread.currentThread();
+ Thread.sleep(1000);
+ }
+ initEntitiesInfo();
+ monitor.worked(1);
+ monitor.done();
+ }
+ });
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ page2.setInput(project_infos);
+ }
+ }
+
public void init(IWorkbench workbench, IStructuredSelection selection) {
- updateSelectedItems(selection);
- initEntitiesInfo();
+ this.selection = selection;
}
-
+
@Override
public boolean performFinish() {
Map<IJavaProject, Configuration> configs = createConfigurations();
@@ -95,13 +141,13 @@
IResource container;
try {
- container = entry.getKey().getPackageFragmentRoots().length > 0
- ? entry.getKey().getPackageFragmentRoots()[0].getResource()
- : entry.getKey().getResource();
-
- HibernateMappingExporter hce = new HibernateMappingExporter(config,
+ container = entry.getKey().getPackageFragmentRoots().length > 0
+ ? entry.getKey().getPackageFragmentRoots()[0].getResource()
+ : entry.getKey().getResource();
+
+ HibernateMappingExporter hce = new HibernateMappingExporter(config,
container.getLocation().toFile());
-
+
hce.setGlobalSettings(hmgs);
//hce.setForEach("entity");
//hce.setFilePattern(file.getName());
@@ -110,7 +156,7 @@
} catch (Exception e){
e.getCause().printStackTrace();
}
- container.refreshLocal(IResource.DEPTH_INFINITE, null);
+ container.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (JavaModelException e1) {
HibernateConsolePlugin.getDefault().log(e1);
} catch (CoreException e) {
@@ -121,8 +167,10 @@
}
protected void initEntitiesInfo(){
- if (selectionCU.size() == 0) return;
- AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
+ if (selectionCU.size() == 0) {
+ return;
+ }
+ AllEntitiesInfoCollector collector = new AllEntitiesInfoCollector();
Iterator<ICompilationUnit> it = selectionCU.iterator();
Map<IJavaProject, Set<ICompilationUnit>> mapJP_CUSet =
@@ -138,10 +186,10 @@
set.add(cu);
}
Iterator<Map.Entry<IJavaProject, Set<ICompilationUnit>>>
- mapIt = mapJP_CUSet.entrySet().iterator();
+ mapIt = mapJP_CUSet.entrySet().iterator();
while (mapIt.hasNext()) {
Map.Entry<IJavaProject, Set<ICompilationUnit>>
- entry = mapIt.next();
+ entry = mapIt.next();
IJavaProject javaProject = entry.getKey();
Iterator<ICompilationUnit> setIt = entry.getValue().iterator();
collector.initCollector(javaProject);
@@ -155,78 +203,7 @@
}
}
-
- private Map<IJavaProject, Configuration> createConfigurations() {
- ConfigurationActor actor = new ConfigurationActor(selectionCU);
- Map<IJavaProject, Configuration> configs = actor.createConfigurations();
- return configs;
- }
- protected void updateSelectedItems(ISelection sel) {
- if (sel instanceof TextSelection) {
- String fullyQualifiedName = ""; //$NON-NLS-1$
- IDocument fDocument = null;
- SynchronizableDocument sDocument = null;
- org.eclipse.jdt.core.dom.CompilationUnit resultCU = null;
- Class clazz = sel.getClass();
- Field fd = null;
- try {
- fd = clazz.getDeclaredField("fDocument"); //$NON-NLS-1$
- } catch (NoSuchFieldException e) {
- // just ignore it!
- }
- if (fd != null) {
- try {
- fd.setAccessible(true);
- fDocument = (IDocument)fd.get(sel);
- if (fDocument instanceof SynchronizableDocument) {
- sDocument = (SynchronizableDocument)fDocument;
- }
- if (sDocument != null) {
- ASTParser parser = ASTParser.newParser(AST.JLS3);
- parser.setSource(sDocument.get().toCharArray());
- parser.setResolveBindings(false);
- resultCU = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
- }
- if (resultCU != null && resultCU.types().size() > 0 ) {
- if (resultCU.getPackage() != null) {
- fullyQualifiedName = resultCU.getPackage().getName().getFullyQualifiedName() +
"."; //$NON-NLS-1$
- }
- else {
- fullyQualifiedName = ""; //$NON-NLS-1$
- }
- Object tmp = resultCU.types().get(0);
- if (tmp instanceof AbstractTypeDeclaration) {
- fullyQualifiedName += ((AbstractTypeDeclaration)tmp).getName();
- }
- if (!(tmp instanceof TypeDeclaration)) {
- // ignore EnumDeclaration & AnnotationTypeDeclaration
- fullyQualifiedName = ""; //$NON-NLS-1$
- }
- }
- } catch (IllegalArgumentException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("IllegalArgumentException:
", e); //$NON-NLS-1$
- } catch (IllegalAccessException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("IllegalAccessException:
", e); //$NON-NLS-1$
- } catch (SecurityException e) {
- HibernateConsolePlugin.getDefault().logErrorMessage("SecurityException: ",
e); //$NON-NLS-1$
- }
- }
- if (fullyQualifiedName.length() > 0) {
- ICompilationUnit cu = Utils.findCompilationUnit(fullyQualifiedName);
- selectionCU.add(cu);
- }
- }
- else if (sel instanceof TreeSelection) {
- TreeSelection treeSelection = (TreeSelection)sel;
- Iterator it = treeSelection.iterator();
- while (it.hasNext()) {
- Object obj = it.next();
- processJavaElements(obj);
- }
- }
- }
-
protected void processJavaElements(Object obj) {
if (obj instanceof ICompilationUnit) {
ICompilationUnit cu = (ICompilationUnit)obj;
@@ -239,8 +216,8 @@
ICompilationUnit[] cus = Utils.findCompilationUnits(javaProject,
file.getFullPath());
if (cus != null) {
- for (int i = 0; i < cus.length; i++) {
- selectionCU.add(cus[i]);
+ for (ICompilationUnit cu : cus) {
+ selectionCU.add(cu);
}
}
}
@@ -255,8 +232,8 @@
//HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
if (pfr != null) {
- for (int i = 0; i < pfr.length; i++) {
- processJavaElements(pfr[i]);
+ for (IPackageFragmentRoot element : pfr) {
+ processJavaElements(element);
}
}
}
@@ -270,13 +247,12 @@
//HibernateConsolePlugin.getDefault().logErrorMessage("JavaModelException:
", e); //$NON-NLS-1$
}
if (cus != null) {
- for (int i = 0; i < cus.length; i++) {
- selectionCU.add(cus[i]);
+ for (ICompilationUnit cu : cus) {
+ selectionCU.add(cu);
}
}
}
else if (obj instanceof PackageFragmentRoot) {
- PackageFragmentRoot packageFragmentRoot = (PackageFragmentRoot)obj;
JavaElement javaElement = (JavaElement)obj;
JavaElementInfo javaElementInfo = null;
try {
@@ -287,8 +263,8 @@
}
if (javaElementInfo != null) {
IJavaElement[] je = javaElementInfo.getChildren();
- for (int i = 0; i < je.length; i++) {
- processJavaElements(je[i]);
+ for (IJavaElement element : je) {
+ processJavaElements(element);
}
}
}
@@ -299,4 +275,11 @@
}
}
+
+ protected Map<IJavaProject, Configuration> createConfigurations() {
+ ConfigurationActor actor = new ConfigurationActor(selectionCU);
+ Map<IJavaProject, Configuration> configs = actor.createConfigurations();
+ return configs;
+ }
+
}