diff options
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen')
5 files changed, 0 insertions, 1800 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/AbstractJarDestinationWizardPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/AbstractJarDestinationWizardPage.java deleted file mode 100644 index b703e1c3bb..0000000000 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/AbstractJarDestinationWizardPage.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2010 Oracle. All rights reserved. -* This program and the accompanying materials are 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. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen; - -import org.eclipse.jdt.ui.jarpackager.JarPackageData; -import org.eclipse.jface.viewers.IStructuredSelection; - -/** - * Façade class to change accessibility of AbstractJarDestinationWizardPage. - */ -@SuppressWarnings("restriction") -public abstract class AbstractJarDestinationWizardPage extends org.eclipse.jdt.internal.ui.jarpackager.AbstractJarDestinationWizardPage -{ - - public AbstractJarDestinationWizardPage(String pageName, IStructuredSelection selection, JarPackageData jarPackage) { - super(pageName, selection, jarPackage); - } - -} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java deleted file mode 100644 index e551a5e32f..0000000000 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/CheckboxTreeAndListGroup.java +++ /dev/null @@ -1,856 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Code originate from org.eclipse.jdt.internal.ui.jarpackager - *******************************************************************************/ -package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.ITreeViewerListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeExpansionEvent; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Tree; - -/** - * Combines a CheckboxTreeViewer and CheckboxListViewer. - * All viewer selection-driven interactions are handled within this viewer - */ -public class CheckboxTreeAndListGroup implements ICheckStateListener, ISelectionChangedListener, ITreeViewerListener { - - private Object fRoot; - private Object fCurrentTreeSelection; - private List fExpandedTreeNodes= new ArrayList(); - private Map fCheckedStateStore= this.buildCheckedStateStore(); - private List fWhiteCheckedTreeItems= new ArrayList(); - private List fListeners= new ArrayList(); - - private ITreeContentProvider fTreeContentProvider; - private IStructuredContentProvider fListContentProvider; - private ILabelProvider fTreeLabelProvider; - private ILabelProvider fListLabelProvider; - - // widgets - private CheckboxTreeViewer fTreeViewer; - private CheckboxTableViewer fListViewer; - - /** - * Creates an instance of this class. Use this constructor if you wish to specify - * the width and/or height of the combined widget (to only hardcode one of the - * sizing dimensions, specify the other dimension's value as -1) - * @param parent parent composite - * @param rootObject - * @param treeContentProvider - * @param treeLabelProvider - * @param listContentProvider - * @param listLabelProvider - * @param style - * @param width the width - * @param height the height - */ - public CheckboxTreeAndListGroup( - Composite parent, - Object rootObject, - ITreeContentProvider treeContentProvider, - ILabelProvider treeLabelProvider, - IStructuredContentProvider listContentProvider, - ILabelProvider listLabelProvider, - int style, - int width, - int height) { - fRoot= rootObject; - fTreeContentProvider= treeContentProvider; - fListContentProvider= listContentProvider; - fTreeLabelProvider= treeLabelProvider; - fListLabelProvider= listLabelProvider; - createContents(parent, width, height, style); - } - /** - * This method must be called just before this window becomes visible. - */ - public void aboutToOpen() { - determineWhiteCheckedDescendents(fRoot); - checkNewTreeElements(getTreeChildren(fRoot)); - fCurrentTreeSelection= null; - - //select the first element in the list - Object[] elements= getTreeChildren(fRoot); - Object primary= elements.length > 0 ? elements[0] : null; - if (primary != null) { - fTreeViewer.setSelection(new StructuredSelection(primary)); - } - fTreeViewer.getControl().setFocus(); - } - /** - * Adds the passed listener to self's collection of clients - * that listen for changes to element checked states - * - * @param listener ICheckStateListener - */ - public void addCheckStateListener(ICheckStateListener listener) { - fListeners.add(listener); - } - /** - * Adds the receiver and all of it's ancestors to the checkedStateStore if they - * are not already there. - * @param treeElement - */ - private void addToHierarchyToCheckedStore(Object treeElement) { - - // if this tree element is already gray then its ancestors all are as well - if (!fCheckedStateStore.containsKey(treeElement)) - fCheckedStateStore.put(treeElement, new ArrayList()); - - Object parent= fTreeContentProvider.getParent(treeElement); - if (parent != null) - addToHierarchyToCheckedStore(parent); - } - /** - * Returns a boolean indicating whether all children of the passed tree element - * are currently white-checked - * - * @return boolean - * @param treeElement java.lang.Object - */ - protected boolean areAllChildrenWhiteChecked(Object treeElement) { - Object[] children= getTreeChildren(treeElement); - for (int i= 0; i < children.length; ++i) { - if (!fWhiteCheckedTreeItems.contains(children[i])) - return false; - } - - return true; - } - /** - * Returns a boolean indicating whether all list elements associated with - * the passed tree element are currently checked - * - * @return boolean - * @param treeElement java.lang.Object - */ - protected boolean areAllElementsChecked(Object treeElement) { - List checkedElements= (List)fCheckedStateStore.get(treeElement); - if (checkedElements == null) // ie.- tree item not even gray-checked - return false; - - return getListItemsSize(treeElement) == checkedElements.size(); - } - /** - * Iterates through the passed elements which are being realized for the first - * time and check each one in the tree viewer as appropriate - * @param elements - */ - protected void checkNewTreeElements(Object[] elements) { - for (int i= 0; i < elements.length; ++i) { - Object currentElement= elements[i]; - boolean checked= fCheckedStateStore.containsKey(currentElement); - fTreeViewer.setChecked(currentElement, checked); - fTreeViewer.setGrayed( - currentElement, - checked && !fWhiteCheckedTreeItems.contains(currentElement)); - } - } - /** - * An item was checked in one of self's two views. Determine which - * view this occurred in and delegate appropriately - * - * @param event CheckStateChangedEvent - */ - public void checkStateChanged(final CheckStateChangedEvent event) { - - //Potentially long operation - show a busy cursor - BusyIndicator.showWhile(fTreeViewer.getControl().getDisplay(), new Runnable() { - public void run() { - if (event.getCheckable().equals(fTreeViewer)) - treeItemChecked(event.getElement(), event.getChecked()); - else - listItemChecked(event.getElement(), event.getChecked(), true); - - notifyCheckStateChangeListeners(event); - } - }); - } - /** - * Lay out and initialize self's visual components. - * - * @param parent org.eclipse.swt.widgets.Composite - * @param width int - * @param height int - * @param style - */ - protected void createContents( - Composite parent, - int width, - int height, - int style) { - // group pane - Composite composite= new Composite(parent, style); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.makeColumnsEqualWidth= true; - layout.marginHeight= 0; - layout.marginWidth= 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - - createTreeViewer(composite, width / 2, height); - createListViewer(composite, width / 2, height); - - initialize(); - } - /** - * Creates this group's list viewer. - * @param parent the parent composite - * @param width the width - * @param height the height - */ - protected void createListViewer(Composite parent, int width, int height) { - fListViewer= CheckboxTableViewer.newCheckList(parent, SWT.BORDER); - fListViewer.setUseHashlookup(true); - GridData data= new GridData(GridData.FILL_BOTH); - data.widthHint= width; - data.heightHint= height; - fListViewer.getTable().setLayoutData(data); - fListViewer.setContentProvider(fListContentProvider); - fListViewer.setLabelProvider(fListLabelProvider); - fListViewer.addCheckStateListener(this); - } - /** - * Creates this group's tree viewer. - * @param parent parent composite - * @param width the width - * @param height the height - */ - protected void createTreeViewer(Composite parent, int width, int height) { - Tree tree= new Tree(parent, SWT.CHECK | SWT.BORDER); - GridData data= new GridData(GridData.FILL_BOTH); - data.widthHint= width; - data.heightHint= height; - tree.setLayoutData(data); - - fTreeViewer= new CheckboxTreeViewer(tree); - fTreeViewer.setUseHashlookup(true); - fTreeViewer.setContentProvider(fTreeContentProvider); - fTreeViewer.setLabelProvider(fTreeLabelProvider); - fTreeViewer.addTreeListener(this); - fTreeViewer.addCheckStateListener(this); - fTreeViewer.addSelectionChangedListener(this); - } - /** - * Returns a boolean indicating whether the passed tree element should be - * at LEAST gray-checked. Note that this method does not consider whether - * it should be white-checked, so a specified tree item which should be - * white-checked will result in a <code>true</code> answer from this method. - * To determine whether a tree item should be white-checked use method - * #determineShouldBeWhiteChecked(Object). - * - * @param treeElement java.lang.Object - * @return boolean - * @see #determineShouldBeWhiteChecked(java.lang.Object) - */ - protected boolean determineShouldBeAtLeastGrayChecked(Object treeElement) { - // if any list items associated with treeElement are checked then it - // retains its gray-checked status regardless of its children - List checked= (List) fCheckedStateStore.get(treeElement); - if (checked != null && (!checked.isEmpty())) - return true; - - // if any children of treeElement are still gray-checked then treeElement - // must remain gray-checked as well - Object[] children= getTreeChildren(treeElement); - for (int i= 0; i < children.length; ++i) { - if (fCheckedStateStore.containsKey(children[i])) - return true; - } - - return false; - } - /** - * Returns a boolean indicating whether the passed tree item should be - * white-checked. - * - * @return boolean - * @param treeElement java.lang.Object - */ - protected boolean determineShouldBeWhiteChecked(Object treeElement) { - return areAllChildrenWhiteChecked(treeElement) - && areAllElementsChecked(treeElement); - } - /** - * Recursively adds appropriate tree elements to the collection of - * known white-checked tree elements. - * - * @param treeElement java.lang.Object - */ - protected void determineWhiteCheckedDescendents(Object treeElement) { - // always go through all children first since their white-checked - // statuses will be needed to determine the white-checked status for - // this tree element - Object[] children= getTreeChildren(treeElement); - for (int i= 0; i < children.length; ++i) - determineWhiteCheckedDescendents(children[i]); - - // now determine the white-checked status for this tree element - if (determineShouldBeWhiteChecked(treeElement)) - setWhiteChecked(treeElement, true); - } - /** - * Causes the tree viewer to expand all its items - */ - public void expandAll() { - fTreeViewer.expandAll(); - } - /** - * Answers a flat collection of all of the checked elements in the - * list portion of self - * - * @return java.util.Vector - */ - public Iterator getAllCheckedListItems() { - Set result= new HashSet(); - Iterator listCollectionsEnum= this.fCheckedStateStore.values().iterator(); - while (listCollectionsEnum.hasNext()) - result.addAll((List)listCollectionsEnum.next()); - return result.iterator(); - } - /** - * Answer a collection of all of the checked elements in the tree portion - * of self - * - * @return java.util.Vector - */ - public Set getAllCheckedTreeItems() { - return new HashSet(fCheckedStateStore.keySet()); - } - /** - * Answers the number of elements that have been checked by the - * user. - * - * @return int - */ - public int getCheckedElementCount() { - return fCheckedStateStore.size(); - } - /** - * Returns a count of the number of list items associated with a - * given tree item. - * - * @return int - * @param treeElement java.lang.Object - */ - protected int getListItemsSize(Object treeElement) { - Object[] elements= getListElements(treeElement); - return elements.length; - } - /** - * Gets the table that displays the folder content - * - * @return the table used to show the list - */ - public Table getTable() { - return fListViewer.getTable(); - } - /** - * Gets the tree that displays the list for a folder - * - * @return the tree used to show the folders - */ - public Tree getTree() { - return fTreeViewer.getTree(); - } - /** - * Adds the given filter to the tree viewer and - * triggers refiltering and resorting of the elements. - * - * @param filter a viewer filter - */ - public void addTreeFilter(ViewerFilter filter) { - fTreeViewer.addFilter(filter); - } - - public void removeTreeFilter(ViewerFilter filter) { - fTreeViewer.removeFilter(filter); - } - - /** - * Adds the given filter to the list viewer and - * triggers refiltering and resorting of the elements. - * - * @param filter a viewer filter - */ - public void addListFilter(ViewerFilter filter) { - fListViewer.addFilter(filter); - } - - /** - * Logically gray-check all ancestors of treeItem by ensuring that they - * appear in the checked table - * @param treeElement - */ - protected void grayCheckHierarchy(Object treeElement) { - - // if this tree element is already gray then its ancestors all are as well - if (fCheckedStateStore.containsKey(treeElement)) - return; // no need to proceed upwards from here - - fCheckedStateStore.put(treeElement, new ArrayList()); - if (determineShouldBeWhiteChecked(treeElement)) { - setWhiteChecked(treeElement, true); - } - Object parent= fTreeContentProvider.getParent(treeElement); - if (parent != null) - grayCheckHierarchy(parent); - } - /** - * Sets the initial checked state of the passed list element to true. - * @param element - */ - public void initialCheckListItem(Object element) { - Object parent= fTreeContentProvider.getParent(element); - fCurrentTreeSelection= parent; - //As this is not done from the UI then set the box for updating from the selection to false - listItemChecked(element, true, false); - updateHierarchy(parent); - } - /** - * Sets the initial checked state of the passed element to true, - * as well as to all of its children and associated list elements - * @param element - */ - public void initialCheckTreeItem(Object element) { - treeItemChecked(element, true); - } - /** - * Initializes this group's viewers after they have been laid out. - */ - protected void initialize() { - fTreeViewer.setInput(fRoot); - } - /** - * Callback that's invoked when the checked status of an item in the list - * is changed by the user. Do not try and update the hierarchy if we are building the - * initial list. - * @param listElement - * @param state - * @param updatingFromSelection - */ - protected void listItemChecked( - Object listElement, - boolean state, - boolean updatingFromSelection) { - List checkedListItems= (List) fCheckedStateStore.get(fCurrentTreeSelection); - - if (state) { - if (checkedListItems == null) { - // since the associated tree item has gone from 0 -> 1 checked - // list items, tree checking may need to be updated - grayCheckHierarchy(fCurrentTreeSelection); - checkedListItems= (List) fCheckedStateStore.get(fCurrentTreeSelection); - } - checkedListItems.add(listElement); - } else { - checkedListItems.remove(listElement); - if (checkedListItems.isEmpty()) { - // since the associated tree item has gone from 1 -> 0 checked - // list items, tree checking may need to be updated - ungrayCheckHierarchy(fCurrentTreeSelection); - } - } - - if (updatingFromSelection) - updateHierarchy(fCurrentTreeSelection); - } - /** - * Notifies all checked state listeners that the passed element has had - * its checked state changed to the passed state - * @param event - */ - protected void notifyCheckStateChangeListeners(CheckStateChangedEvent event) { - Iterator listenersEnum= fListeners.iterator(); - while (listenersEnum.hasNext()) - ((ICheckStateListener) listenersEnum.next()).checkStateChanged(event); - } - /** - *Sets the contents of the list viewer based upon the specified selected - *tree element. This also includes checking the appropriate list items. - * - *@param treeElement java.lang.Object - */ - public void populateListViewer(final Object treeElement) { - if (treeElement == fCurrentTreeSelection) - return; - fCurrentTreeSelection= treeElement; - fListViewer.setInput(treeElement); - List listItemsToCheck= (List) fCheckedStateStore.get(treeElement); - - if (listItemsToCheck != null) { - Iterator listItemsEnum= listItemsToCheck.iterator(); - while (listItemsEnum.hasNext()) - fListViewer.setChecked(listItemsEnum.next(), true); - } - } - /** - * Removes the passed listener from self's collection of clients - * that listen for changes to element checked states - * - * @param listener ICheckStateListener - */ - public void removeCheckStateListener(ICheckStateListener listener) { - fListeners.remove(listener); - } - /** - * Handles the selection of an item in the tree viewer - * - * @param event ISelection - */ - public void selectionChanged(final SelectionChangedEvent event) { - BusyIndicator.showWhile(getTable().getShell().getDisplay(), new Runnable() { - public void run() { - IStructuredSelection selection= (IStructuredSelection) event.getSelection(); - Object selectedElement= selection.getFirstElement(); - if (selectedElement == null) { - fCurrentTreeSelection= null; - fListViewer.setInput(fCurrentTreeSelection); - return; - } - populateListViewer(selectedElement); - } - }); - } - - /** - * Selects or deselect all of the elements in the tree depending on the value of the selection - * boolean. Be sure to update the displayed files as well. - * @param selection - */ - public void setAllSelections(final boolean selection) { - - //Potentially long operation - show a busy cursor - BusyIndicator.showWhile(fTreeViewer.getControl().getDisplay(), new Runnable() { - public void run() { - setTreeChecked(fRoot, selection); - fListViewer.setAllChecked(selection); - } - }); - } - - /** - * Sets the list viewer's providers to those passed - * - * @param contentProvider ITreeContentProvider - * @param labelProvider ILabelProvider - */ - public void setListProviders( - IStructuredContentProvider contentProvider, - ILabelProvider labelProvider) { - fListViewer.setContentProvider(contentProvider); - fListViewer.setLabelProvider(labelProvider); - } - /** - * Sets the sorter that is to be applied to self's list viewer - * @param comparator - */ - public void setListComparator(ViewerComparator comparator) { - fListViewer.setComparator(comparator); - } - /** - * Sets the root of the widget to be new Root. Regenerate all of the tables and lists from this - * value. - * - * @param newRoot - */ - public void setRoot(Object newRoot) { - this.fRoot= newRoot; - initialize(); - } - /** - * Sets the checked state of the passed tree element appropriately, and - * do so recursively to all of its child tree elements as well - * @param treeElement - * @param state - */ - protected void setTreeChecked(Object treeElement, boolean state) { - - if (treeElement.equals(fCurrentTreeSelection)) { - fListViewer.setAllChecked(state); - } - - if (state) { - Object[] listItems= getListElements(treeElement); - List listItemsChecked= new ArrayList(); - for (int i= 0; i < listItems.length; ++i) - listItemsChecked.add(listItems[i]); - - fCheckedStateStore.put(treeElement, listItemsChecked); - } else - fCheckedStateStore.remove(treeElement); - - setWhiteChecked(treeElement, state); - fTreeViewer.setChecked(treeElement, state); - fTreeViewer.setGrayed(treeElement, false); - - // now logically check/uncheck all children as well - Object[] children= getTreeChildren(treeElement); - for (int i= 0; i < children.length; ++i) { - setTreeChecked(children[i], state); - } - } - /** - * Sets the tree viewer's providers to those passed - * - * @param contentProvider ITreeContentProvider - * @param labelProvider ILabelProvider - */ - public void setTreeProviders( - ITreeContentProvider contentProvider, - ILabelProvider labelProvider) { - fTreeViewer.setContentProvider(contentProvider); - fTreeViewer.setLabelProvider(labelProvider); - } - /** - * Sets the sorter that is to be applied to self's tree viewer - * @param sorter - */ - public void setTreeComparator(ViewerComparator sorter) { - fTreeViewer.setComparator(sorter); - } - /** - * Adjusts the collection of references to white-checked tree elements appropriately. - * - * @param treeElement java.lang.Object - * @param isWhiteChecked boolean - */ - protected void setWhiteChecked(Object treeElement, boolean isWhiteChecked) { - if (isWhiteChecked) { - if (!fWhiteCheckedTreeItems.contains(treeElement)) - fWhiteCheckedTreeItems.add(treeElement); - } else - fWhiteCheckedTreeItems.remove(treeElement); - } - /** - * Handle the collapsing of an element in a tree viewer - * @param event - */ - public void treeCollapsed(TreeExpansionEvent event) { - // We don't need to do anything with this - } - - /** - * Handles the expansionsion of an element in a tree viewer - * @param event - */ - public void treeExpanded(TreeExpansionEvent event) { - - Object item= event.getElement(); - - // First see if the children need to be given their checked state at all. If they've - // already been realized then this won't be necessary - if (!fExpandedTreeNodes.contains(item)) { - fExpandedTreeNodes.add(item); - checkNewTreeElements(getTreeChildren(item)); - } - } - - /** - * Callback that's invoked when the checked status of an item in the tree - * is changed by the user. - * @param treeElement - * @param state - */ - protected void treeItemChecked(Object treeElement, boolean state) { - - // recursively adjust all child tree elements appropriately - setTreeChecked(treeElement, state); - - Object parent= fTreeContentProvider.getParent(treeElement); - if (parent == null) - return; - - // now update upwards in the tree hierarchy - if (state) - grayCheckHierarchy(parent); - else - ungrayCheckHierarchy(parent); - - updateHierarchy(treeElement); - } - /** - * Logically un-gray-check all ancestors of treeItem iff appropriate. - * @param treeElement - */ - protected void ungrayCheckHierarchy(Object treeElement) { - if (!determineShouldBeAtLeastGrayChecked(treeElement)) - fCheckedStateStore.remove(treeElement); - - Object parent= fTreeContentProvider.getParent(treeElement); - if (parent != null) - ungrayCheckHierarchy(parent); - } - /** - * Sets the checked state of self and all ancestors appropriately - * @param treeElement - */ - protected void updateHierarchy(Object treeElement) { - - boolean whiteChecked= determineShouldBeWhiteChecked(treeElement); - boolean shouldBeAtLeastGray= determineShouldBeAtLeastGrayChecked(treeElement); - - fTreeViewer.setChecked(treeElement, whiteChecked || shouldBeAtLeastGray); - setWhiteChecked(treeElement, whiteChecked); - if (whiteChecked) - fTreeViewer.setGrayed(treeElement, false); - else - fTreeViewer.setGrayed(treeElement, shouldBeAtLeastGray); - - // proceed up the tree element hierarchy - Object parent= fTreeContentProvider.getParent(treeElement); - if (parent != null) { - updateHierarchy(parent); - } - } - /** - * Update the selections of the tree elements in items to reflect the new - * selections provided. - * - * @param items with keys of Object (the tree element) and values of List (the selected - * list elements). - */ - public void updateSelections(final Map items) { - - //Potentially long operation - show a busy cursor - BusyIndicator.showWhile(fTreeViewer.getControl().getDisplay(), new Runnable() { - public void run() { - handleUpdateSelection(items); - } - }); - } - /** - * Returns the result of running the given elements through the filters. - * @param filters - * - * @param elements the elements to filter - * @return only the elements which all filters accept - */ - protected Object[] filter(ViewerFilter[] filters, Object[] elements) { - if (filters != null) { - ArrayList filtered = new ArrayList(elements.length); - for (int i = 0; i < elements.length; i++) { - boolean add = true; - for (int j = 0; j < filters.length; j++) { - add = filters[j].select(null, null, elements[i]); - if (!add) - break; - } - if (add) - filtered.add(elements[i]); - } - return filtered.toArray(); - } - return elements; - } - - private Object[] getTreeChildren(Object element) { - return filter(fTreeViewer.getFilters(), fTreeContentProvider.getChildren(element)); - } - - private Object[] getListElements(Object element) { - return filter(fListViewer.getFilters(), fListContentProvider.getElements(element)); - } - - public Set getWhiteCheckedTreeItems() { - return new HashSet(fWhiteCheckedTreeItems); - } - - private HashMap buildCheckedStateStore() { - return new HashMap(9); - } - - private void handleUpdateSelection(Map items) { - Iterator keyIterator= items.keySet().iterator(); - - //Update the store before the hierarchy to prevent updating parents before all of the children are done - while (keyIterator.hasNext()) { - Object key= keyIterator.next(); - //Replace the items in the checked state store with those from the supplied items - List selections= (List) items.get(key); - if (selections.size() == 0) - //If it is empty remove it from the list - fCheckedStateStore.remove(key); - else { - fCheckedStateStore.put(key, selections); - // proceed up the tree element hierarchy - Object parent= fTreeContentProvider.getParent(key); - if (parent != null) { - addToHierarchyToCheckedStore(parent); - } - } - } - - //Now update hierarchies - keyIterator= items.keySet().iterator(); - - while (keyIterator.hasNext()) { - Object key= keyIterator.next(); - updateHierarchy(key); - if (fCurrentTreeSelection != null && fCurrentTreeSelection.equals(key)) { - fListViewer.setAllChecked(false); - fListViewer.setCheckedElements(((List) items.get(key)).toArray()); - } - } - } - - /** - * Checks if an element is grey checked. - * @param object - * @return if an element is grey checked. - */ - public boolean isTreeItemGreyChecked(Object object) { - return fTreeViewer.getGrayed(object); - } - - /** - * For a given element, expand its chidren to a level. - * @param object - * @param level - */ - public void expandTreeToLevel(Object object, int level) { - fTreeViewer.expandToLevel(object, level); - } - /** - * @param selection - */ - public void setTreeSelection(ISelection selection) { - fTreeViewer.setSelection(selection); - } -}
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java deleted file mode 100644 index d6fcb911bf..0000000000 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/NewSchemaFileWizardPage.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2010, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are 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. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen; - -import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.CONTAINER_PATH; -import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.FILE_NAME; -import static org.eclipse.jpt.common.core.internal.operations.JptFileCreationDataModelProperties.PROJECT; -import static org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen.SchemaGeneratorWizard.XSD_EXTENSION; - -import java.io.File; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.common.utility.internal.FileTools; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.dialogs.WizardNewFileCreationPage; -import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * NewSchemaFileWizardPage - */ -public class NewSchemaFileWizardPage extends WizardNewFileCreationPage { - - protected IDataModel dataModel; - - private IStructuredSelection initialSelection; - - static public String DEFAULT_SCHEMA_NAME = "NewXMLSchema" + XSD_EXTENSION; //$NON-NLS-1$ - - // ********** constructor ********** - - public NewSchemaFileWizardPage(String pageName, IStructuredSelection selection, IDataModel dataModel, - String title, String description) { - - super(pageName, selection); - this.initialSelection = selection; - - this.init(dataModel); - this.setTitle(title); - this.setDescription(description); - } - - protected void init(IDataModel dataModel) { - this.dataModel = dataModel; - - IProject project = this.getProjectFromInitialSelection(); - this.dataModel.setProperty(PROJECT, project); - - IPath containerPath = (IPath) this.dataModel.getProperty(CONTAINER_PATH); - if (containerPath != null) { - this.setContainerFullPath(containerPath); - } - } - - // ********** IDialogPage implementation ********** - @Override - public void createControl(Composite parent) { - super.createControl(parent); - - this.setAllowExistingResources(true); - this.setFileName(DEFAULT_SCHEMA_NAME); - } - - // ********** intra-wizard methods ********** - - public IProject getProject() { - return (IProject) this.dataModel.getProperty(PROJECT); - } - - /** - * @return the path of the schema file relative to the project - */ - public IPath getFileRelativePath() { - IPath filePath = this.getContainerFullPath(); - String projectName = filePath.segment(0); - - if(this.getProject().getName().equals(projectName)) { - filePath = filePath.removeFirstSegments(1); - } - return filePath; - } - - // ********** validation ********** - - @Override - protected boolean validatePage() { - this.dataModel.setProperty(PROJECT, this.getProjectNamed(this.getContainerName())); - this.dataModel.setProperty(CONTAINER_PATH, this.getContainerFullPath()); - this.dataModel.setProperty(FILE_NAME, this.getFileName()); - - boolean valid = super.validatePage(); - if( ! valid) { - return valid; - } - this.overrideFileExistsWarning(); - - //TODO move this validation to the dataModel - see MappingFileNewFileWizardPage - // Validate Project - valid = this.projectIsJavaProject(this.getProject()); - if( ! valid) { - this.setErrorMessage(JptJaxbUiMessages.NewSchemaFileWizardPage_errorNotJavaProject); - return valid; - } - // Validate XSD file not exists. - valid = this.xsdFileNotExists(); - if( ! valid) { - this.setMessage(JptJaxbUiMessages.NewSchemaFileWizardPage_overwriteExistingSchemas, IMessageProvider.WARNING); - return true; - } - this.setErrorMessage(null); - - return valid; - } - - // ********** internal methods ********** - - private boolean projectIsJavaProject(IProject project) { - try { - return (project != null) && (project.hasNature(JavaCore.NATURE_ID)); - } - catch (CoreException e) { - return false; - } - } - - private IProject getProjectFromInitialSelection() { - Object firstElement = initialSelection.getFirstElement(); - if(firstElement instanceof IProject) { - return (IProject)firstElement; - } - else if(firstElement instanceof IResource) { - return ((IResource) firstElement).getProject(); - } - else if(firstElement instanceof IJavaElement) { - return ((IJavaElement)firstElement).getJavaProject().getProject(); - } - return null; - } - - private IProject getProjectNamed(String projectName) { - if(StringTools.stringIsEmpty(projectName)) { - return null; - } - return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - } - - private String getContainerName() { - IPath containerPath = this.getContainerFullPath(); - if(containerPath == null) { - return null; - } - String containerName = containerPath.segment(0); - return containerName; - } - - private void overrideFileExistsWarning() { - String existsString= IDEWorkbenchMessages.ResourceGroup_nameExists; - existsString.toString(); - - existsString = existsString.substring("''{0}''".length(), existsString.length()); //$NON-NLS-1$ - String message = this.getMessage(); - if(message != null && message.endsWith(existsString)) { - this.setMessage(null); - } - } - - private boolean xsdFileNotExists() { - - return ! this.xsdFileExists(this.getContainerAbsolutePath().toFile()); - } - - private boolean xsdFileExists(File directory) { - - if(directory.listFiles() == null) { - throw new RuntimeException("Could not find directory: " + directory); //$NON-NLS-1$ - } - for(File file : directory.listFiles()) { - if (file.isDirectory()) { - continue; - } - else if(XSD_EXTENSION.equalsIgnoreCase(FileTools.extension(file))) { - return true; - } - } - return false; - } - - private IPath getContainerAbsolutePath() { - IPath projectRelativePath = this.getContainerFullPath().makeRelativeTo(this.getProject().getFullPath()); - IResource directory = (projectRelativePath.isEmpty()) ? - this.getProject() : - this.getProject().getFile(projectRelativePath); - return directory.getLocation(); - } - -} diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java deleted file mode 100644 index 7b1dc1c747..0000000000 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizard.java +++ /dev/null @@ -1,266 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2010, 2011 Oracle. All rights reserved. -* This program and the accompanying materials are 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. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.FileTools; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jaxb.core.internal.gen.SchemaGenerator; -import org.eclipse.jpt.jaxb.core.internal.operations.SchemaFileCreationDataModelProvider; -import org.eclipse.jpt.jaxb.ui.JptJaxbUiPlugin; -import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiIcons; -import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; -import org.eclipse.osgi.util.NLS; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider; - -/** - * SchemaGeneratorWizard - */ -public class SchemaGeneratorWizard extends Wizard implements INewWizard -{ - protected IStructuredSelection initialSelection; - private IJavaProject targetProject; - - protected IDataModel dataModel; - - private NewSchemaFileWizardPage newSchemaFileWizardPage; - - private SchemaGeneratorWizardPage schemaGenWizardPage; - - public static final String XSD_EXTENSION = ".xsd"; //$NON-NLS-1$ - - // ********** constructor ********** - - public SchemaGeneratorWizard() { - super(); - setWindowTitle(JptJaxbUiMessages.SchemaGeneratorWizard_title); - setDefaultPageImageDescriptor(JptJaxbUiPlugin.getImageDescriptor(JptJaxbUiIcons.SCHEMA_GEN_WIZ_BANNER)); - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - this.initialSelection = selection; - - if (selection == null || selection.isEmpty()) { - return; - } - this.targetProject = this.getProjectFromInitialSelection(); - this.dataModel = null; - } - - // ********** IWizard implementation ********** - - @Override - public void addPages() { - super.addPages(); - - this.newSchemaFileWizardPage = this.buildNewSchemaFileWizardPage(this.initialSelection); - this.addPage(this.newSchemaFileWizardPage); - - this.schemaGenWizardPage = this.buildSchemaGeneratorWizardPage(this.buildSelection(this.getProject())); - this.addPage(this.schemaGenWizardPage); - } - - @Override - public boolean performFinish() { - - this.targetProject = this.getJavaProject(); - - String[] sourceClassNames = this.buildSourceClassNames(this.getAllCheckedItems()); - - WorkspaceJob genSchemaJob = new GenerateSchemaJob( - this.targetProject, - sourceClassNames, - this.getTargetSchema(), - this.usesMoxy()); - genSchemaJob.schedule(); - - return true; - } - - // ********** intra-wizard methods ********** - - public IJavaProject getJavaProject() { - return this.getJavaProjectFrom(this.getProject()); - } - - // ********** internal methods ********** - - private IProject getProject() { - return this.newSchemaFileWizardPage.getProject(); - } - - private IJavaProject getProjectFromInitialSelection() { - IJavaProject project = null; - - Object firstElement = this.initialSelection.getFirstElement(); - if(firstElement instanceof IJavaElement) { - IJavaElement javaElement = (IJavaElement)firstElement; - int type = javaElement.getElementType(); - if(type == IJavaElement.JAVA_PROJECT) { - project = (IJavaProject)javaElement; - } - else if(type == IJavaElement.PACKAGE_FRAGMENT) { - project = ((IPackageFragment)javaElement).getJavaProject(); - } - } - return project; - } - - private IJavaProject getJavaProjectFrom(IProject project) { - IJavaProject javaProject = (IJavaProject)((IJavaElement)((IAdaptable)project).getAdapter(IJavaElement.class)); - if(javaProject == null) { - throw new RuntimeException("Not a Java Project"); //$NON-NLS-1$ - } - return javaProject; - } - - private String getTargetSchema() { - - IPath filePath = this.newSchemaFileWizardPage.getFileRelativePath(); - String fileName = this.newSchemaFileWizardPage.getFileName(); - String targetSchema = (filePath.isEmpty()) ? - fileName : - filePath.toOSString() + File.separator + fileName; - - return this.addXsdExtension(targetSchema); - } - - private String addXsdExtension(String fileName) { - - return (FileTools.extension(fileName).equalsIgnoreCase(XSD_EXTENSION)) ? - fileName : - fileName + XSD_EXTENSION; - } - - private Object[] getAllCheckedItems() { - return this.schemaGenWizardPage.getAllCheckedItems(); - } - - private String[] buildSourceClassNames(Object[] checkedElements) { - - ArrayList<String> classNames = new ArrayList<String>(); - - for(Object element: checkedElements) { - IJavaElement javaElement = (IJavaElement)element; - String packageName = javaElement.getParent().getElementName(); - String elementName = javaElement.getElementName(); - String className = FileTools.stripExtension(elementName); - if(StringTools.stringIsEmpty(packageName)) { - classNames.add(className); - } - else { - classNames.add(packageName + '.' + className); - } - } - - return ArrayTools.array(classNames, new String[0]); - } - - private boolean usesMoxy() { - return this.schemaGenWizardPage.usesMoxy(); - } - - protected NewSchemaFileWizardPage buildNewSchemaFileWizardPage(IStructuredSelection selection) { - return new NewSchemaFileWizardPage( - "Page_1", selection, this.getDataModel(), //$NON-NLS-1$ - JptJaxbUiMessages.SchemaGeneratorProjectWizardPage_title, - JptJaxbUiMessages.SchemaGeneratorProjectWizardPage_desc); - } - - protected SchemaGeneratorWizardPage buildSchemaGeneratorWizardPage(IStructuredSelection selection) { - return new SchemaGeneratorWizardPage(selection); - } - - private IStructuredSelection buildSelection(IProject project) { - - List<IAdaptable> selectedElements = new ArrayList<IAdaptable>(1); - this.addProjectTo(selectedElements, project); - return new StructuredSelection(selectedElements); - } - - private void addProjectTo(List<IAdaptable> selectedElements, IProject project) { - try { - if(project != null && project.hasNature(JavaCore.NATURE_ID)) - selectedElements.add(JavaCore.create(project)); - } - catch(CoreException ex) { - // ignore selected element - } - } - - protected IDataModel getDataModel() { - if (this.dataModel == null) { - this.dataModel = DataModelFactory.createDataModel(getDefaultProvider()); - } - return this.dataModel; - } - - protected IDataModelProvider getDefaultProvider() { - return new SchemaFileCreationDataModelProvider(); - } - - // ********** generate schema job ********** - - static class GenerateSchemaJob extends WorkspaceJob { - private final IJavaProject javaProject; - private final String[] sourceClassNames; - private final String targetSchema; - private final boolean useMoxy; - - GenerateSchemaJob(IJavaProject project, String[] sourceClassNames, String targetSchema, boolean useMoxy) { - super(JptJaxbUiMessages.SchemaGeneratorWizard_generatingSchema); - - this.javaProject = project ; - this.sourceClassNames = sourceClassNames; - this.targetSchema = targetSchema; - this.useMoxy = useMoxy; - - this.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(this.javaProject.getProject())); - } - - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - SubMonitor sm = SubMonitor.convert(monitor, NLS.bind(JptJaxbUiMessages.SchemaGeneratorWizard_generateSchemaTask, this.targetSchema), 1); - try { - SchemaGenerator.generate(this.javaProject, this.targetSchema, this.sourceClassNames, this.useMoxy, sm.newChild(1)); - } - catch (OperationCanceledException e) { - return Status.CANCEL_STATUS; - } - return Status.OK_STATUS; - } - } -}
\ No newline at end of file diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java b/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java deleted file mode 100644 index 70aa054611..0000000000 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/wizards/schemagen/SchemaGeneratorWizardPage.java +++ /dev/null @@ -1,439 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2010 Oracle. All rights reserved. -* This program and the accompanying materials are 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. -* -* Contributors: -* Oracle - initial API and implementation -*******************************************************************************/ -package org.eclipse.jpt.jaxb.ui.internal.wizards.schemagen; - -import java.util.Iterator; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Platform; -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.ui.JavaElementComparator; -import org.eclipse.jdt.ui.JavaElementLabelProvider; -import org.eclipse.jdt.ui.ProblemsLabelDecorator; -import org.eclipse.jdt.ui.StandardJavaElementContentProvider; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.DecoratingLabelProvider; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.jaxb.core.internal.gen.SchemaGenerator; -import org.eclipse.jpt.jaxb.ui.internal.JptJaxbUiMessages; -import org.eclipse.jpt.jaxb.ui.internal.filters.ContainerFilter; -import org.eclipse.jpt.jaxb.ui.internal.filters.EmptyInnerPackageFilter; -import org.eclipse.jpt.jaxb.ui.internal.filters.NonArchiveOrExternalElementFilter; -import org.eclipse.jpt.jaxb.ui.internal.filters.NonContainerFilter; -import org.eclipse.jpt.jaxb.ui.internal.filters.NonJavaElementFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.PlatformUI; -import org.osgi.framework.Bundle; - -/** - * SchemaGeneratorWizardPage - */ -public class SchemaGeneratorWizardPage extends AbstractJarDestinationWizardPage { - - private IJavaProject targetProject; - - // widgets - private SettingsGroup settingsGroup; - private NonContainerFilter projectFilter; - - private Button usesMoxyCheckBox; - private boolean usesMoxy; - - static public String JPT_ECLIPSELINK_UI_PLUGIN_ID = "org.eclipse.jpt.jpa.eclipselink.ui"; //$NON-NLS-1$ - - // other constants - private static final int SIZING_SELECTION_WIDGET_WIDTH = 480; - private static final int SIZING_SELECTION_WIDGET_HEIGHT = 150; - - public static final String HELP_CONTEXT_ID = "org.eclipse.jpt.ui.wizard_jaxbschema_classes"; //$NON-NLS-1$ - - // ********** constructor ********** - - public SchemaGeneratorWizardPage(IStructuredSelection selection) { - super("JAXB Schema Generator", selection, null); //$NON-NLS-1$ - - this.setUsesMoxy(false); - this.setTitle(JptJaxbUiMessages.SchemaGeneratorWizardPage_title); - this.setDescription(JptJaxbUiMessages.SchemaGeneratorWizardPage_desc); - } - - // ********** IDialogPage implementation ********** - @Override - public void createControl(Composite parent) { - this.setPageComplete(false); - this.setControl(this.buildTopLevelControl(parent)); - } - - @Override - public void setVisible(boolean visible) { - super.setVisible(visible); - - if(visible) { - this.updateTargetProject(); - this.updateInputGroupTreeFilter(); - - // default usesMoxy to true only when JPT EclipseLink bundle exists and MOXy is on the classpath - this.updateUsesMoxy(this.jptEclipseLinkBundleExists() && this.moxyIsOnClasspath()); - - // checkbox visible only if jpt.eclipselink.ui plugin is available - // and EclipseLink MOXy is not on the classpath - this.usesMoxyCheckBox.setVisible(this.jptEclipseLinkBundleExists() && ! this.moxyIsOnClasspath()); - - this.validateProjectClasspath(); - } - } - - // ********** IWizardPage implementation ********** - - @Override - public boolean isPageComplete() { - boolean complete = this.validateSourceGroup(); - if(complete) { - this.validateProjectClasspath(); - } - return complete; - } - - @Override - public void setPreviousPage(IWizardPage page) { - super.setPreviousPage(page); - if(this.getControl() != null) - this.updatePageCompletion(); - } - - // ********** intra-wizard methods ********** - - protected Object[] getAllCheckedItems() { - return ArrayTools.array(this.getInputGroup().getAllCheckedListItems()); - } - - protected boolean usesMoxy() { - return this.usesMoxy; - } - - // ********** validation ********** - - @Override - @SuppressWarnings("restriction") - protected void updatePageCompletion() { - super.updatePageCompletion(); - } - - @Override - protected boolean validateDestinationGroup() { - // do nothing - return true; - } - - @Override - protected boolean validateSourceGroup() { - if(this.getAllCheckedItems().length == 0) { - if(this.getErrorMessage() == null) { - this.setErrorMessage(JptJaxbUiMessages.SchemaGeneratorWizardPage_errorNoPackage); - } - return false; - } - this.setErrorMessage(null); - return true; - } - - private void validateProjectClasspath() { - if(this.targetProject == null) { // project selected available yet - return; - } - //this line will suppress the "default package" warning (which doesn't really apply here - //as the JAXB gen uses an org.example.schemaName package by default) and will clear the classpath warnings when necessary - setMessage(null); - - if( ! this.genericJaxbIsOnClasspath()) { - this.displayWarning(JptJaxbUiMessages.SchemaGeneratorWizardPage_jaxbLibrariesNotAvailable); - } - else if(this.usesMoxy() && ! this.moxyIsOnClasspath()) { - //this message is being truncated by the wizard width in some cases - this.displayWarning(JptJaxbUiMessages.SchemaGeneratorWizardPage_moxyLibrariesNotAvailable); - } - - //this code will intelligently remove our classpath warnings when they are present but no longer apply (as an alternative - //to setting the message to null continuously as is currently done) -// else if( this.getMessage() != null){ -// if (this.getMessage().equals(JptJaxbUiMessages.ClassesGeneratorWizardPage_jaxbLibrariesNotAvailable) || -// this.getMessage().equals(JptJaxbUiMessages.ClassesGeneratorWizardPage_moxyLibrariesNotAvailable)) { -// setMessage(null); -// } -// } - } - - /** - * Test if the Jaxb compiler is on the classpath. - */ - private boolean genericJaxbIsOnClasspath() { - try { - String className = SchemaGenerator.JAXB_GENERIC_SCHEMA_GEN_CLASS; - IType genClass = this.targetProject.findType(className); - return (genClass != null); - } - catch(JavaModelException e) { - throw new RuntimeException(e); - } - } - - // ********** internal methods ********** - - private Control buildTopLevelControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout()); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, HELP_CONTEXT_ID); - - this.settingsGroup = new SettingsGroup(composite); - - this.usesMoxyCheckBox = this.buildUsesMoxyCheckBox(composite); - - Dialog.applyDialogFont(parent); - return composite; - } - - private void updateTargetProject() { - - this.targetProject = ((SchemaGeneratorWizard)this.getWizard()).getJavaProject(); - } - - private void updateInputGroupTreeFilter() { - this.getInputGroup().setAllSelections(false); - - if(this.projectFilter != null) { - this.getInputGroup().removeTreeFilter(this.projectFilter); - } - this.projectFilter = new NonContainerFilter(this.targetProject.getProject().getName()); - this.getInputGroup().addTreeFilter(this.projectFilter); - } - - private boolean jptEclipseLinkBundleExists() { - return (this.getJptEclipseLinkBundle() != null); - } - - private Bundle getJptEclipseLinkBundle() { - return Platform.getBundle(JPT_ECLIPSELINK_UI_PLUGIN_ID); // Cannot reference directly EL plugin. - } - - private void setUsesMoxy(boolean usesMoxy){ - this.usesMoxy = usesMoxy; - } - - private void updateUsesMoxy(boolean usesMoxy){ - this.setUsesMoxy(usesMoxy); - this.usesMoxyCheckBox.setSelection(this.usesMoxy()); - this.validateProjectClasspath(); - } - - /** - * Test if the EclipseLink Jaxb compiler is on the classpath. - */ - private boolean moxyIsOnClasspath() { - try { - String className = SchemaGenerator.JAXB_ECLIPSELINK_SCHEMA_GEN_CLASS; - IType genClass = this.targetProject.findType(className); - return (genClass != null); - } - catch (JavaModelException e) { - throw new RuntimeException(e); - } - } - - private void displayWarning(String message) { - this.setMessage(message, WARNING); - } - - private CheckboxTreeAndListGroup getInputGroup() { - return this.settingsGroup.inputGroup; - } - - // ********** overrides ********** - /** - * Returns an iterator over this page's collection of currently-specified - * elements to be exported. This is the primary element selection facility - * accessor for subclasses. - * - * @return an iterator over the collection of elements currently selected for export - */ - @Override - protected Iterator<?> getSelectedResourcesIterator() { - return this.getInputGroup().getAllCheckedListItems(); - } - - @Override - protected void update() { - this.updatePageCompletion(); - } - - @Override - public final void saveWidgetValues() { - // do nothing - } - - @Override - protected void internalSaveWidgetValues() { - // do nothing - } - - @Override - protected void restoreWidgetValues() { - // do nothing - } - - - @Override - protected void initializeJarPackage() { - // do nothing - } - - @Override - protected void giveFocusToDestination() { - // do nothing - } - - // ********** UI components ********** - - private Button buildUsesMoxyCheckBox(Composite parent) { - - Button checkBox = new Button(parent, SWT.CHECK); - GridData gridData = new GridData(); - gridData.verticalIndent = 10; - checkBox.setLayoutData(gridData); - checkBox.setText(JptJaxbUiMessages.ClassesGeneratorWizardPage_usesMoxyImplementation); - checkBox.setSelection(this.usesMoxy()); - checkBox.addSelectionListener(this.buildUsesMoxySelectionListener()); - - return checkBox; - } - - private SelectionListener buildUsesMoxySelectionListener() { - return new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent event) { - this.widgetSelected(event); - } - - public void widgetSelected(SelectionEvent event) { - updateUsesMoxy(usesMoxyCheckBox.getSelection()); - validateProjectClasspath(); - } - }; - } - - // ********** SettingsGroup class ********** - - private class SettingsGroup { - - private CheckboxTreeAndListGroup inputGroup; - - // ********** constructor ********** - - private SettingsGroup(Composite parent) { - super(); - initializeDialogUnits(parent); - - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - buildSchemaComposite(composite); - - // Input Tree - createPlainLabel(composite, JptJaxbUiMessages.SchemaGeneratorWizardPage_packages); - this.inputGroup = this.createInputGroup(composite); - - } - - protected void buildSchemaComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(3, false); // false = do not make columns equal width - layout.marginWidth = 0; - layout.marginTop = 0; - layout.marginBottom = 10; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - } - - // ********** UI components ********** - - /** - * Creates the checkbox tree and list for selecting resources. - * - * @param parent the parent control - */ - protected CheckboxTreeAndListGroup createInputGroup(Composite parent) { - CheckboxTreeAndListGroup checkboxTreeGroup; - - int labelFlags = JavaElementLabelProvider.SHOW_BASICS - | JavaElementLabelProvider.SHOW_OVERLAY_ICONS - | JavaElementLabelProvider.SHOW_SMALL_ICONS; - ITreeContentProvider treeContentProvider= - new StandardJavaElementContentProvider() { - @Override - public boolean hasChildren(Object element) { - // prevent the + from being shown in front of packages - return !(element instanceof IPackageFragment) && super.hasChildren(element); - } - }; - final DecoratingLabelProvider provider = new DecoratingLabelProvider(new JavaElementLabelProvider(labelFlags), new ProblemsLabelDecorator(null)); - checkboxTreeGroup = new CheckboxTreeAndListGroup( - parent, - JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()), - treeContentProvider, - provider, - new StandardJavaElementContentProvider(), - provider, - SWT.NONE, - SIZING_SELECTION_WIDGET_WIDTH, - SIZING_SELECTION_WIDGET_HEIGHT); - checkboxTreeGroup.addTreeFilter(new EmptyInnerPackageFilter()); - checkboxTreeGroup.setTreeComparator(new JavaElementComparator()); - checkboxTreeGroup.setListComparator(new JavaElementComparator()); - - checkboxTreeGroup.addTreeFilter(new NonJavaElementFilter()); - checkboxTreeGroup.addTreeFilter(new NonArchiveOrExternalElementFilter()); - - checkboxTreeGroup.addListFilter(new ContainerFilter()); - checkboxTreeGroup.addListFilter(new NonJavaElementFilter()); - - checkboxTreeGroup.getTree().addListener(SWT.MouseUp, SchemaGeneratorWizardPage.this); - checkboxTreeGroup.getTable().addListener(SWT.MouseUp, SchemaGeneratorWizardPage.this); - - ICheckStateListener listener = new ICheckStateListener() { - public void checkStateChanged(CheckStateChangedEvent event) { - update(); - } - }; - - checkboxTreeGroup.addCheckStateListener(listener); - return checkboxTreeGroup; - } - } -} |