diff options
Diffstat (limited to 'jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath')
8 files changed, 0 insertions, 2125 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibrariesPreferencePage.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibrariesPreferencePage.java deleted file mode 100644 index db7235285..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibrariesPreferencePage.java +++ /dev/null @@ -1,404 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 Oracle Corporation. - * 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: - * Gerry Kessler - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.PluginProvidedJSFLibrary; -import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; -import org.eclipse.jst.jsf.ui.internal.Messages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -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.swt.widgets.Label; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.IWorkbenchWizard; - -/** - * Provides a preference page for JSF Libraries. - * - * @author Gerry Kessler - Oracle - */ -public class JSFLibrariesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage -{ - private IWorkbench wb; - - private TreeViewer tv; - private TreeViewerAdapter tvAdapter; - private TreeLabelProvider tvLabelProvider; - - private Composite btnComp; - - private Button btnNew; - private Button btnEdit; - private Button btnDelete; - private Button btnMakeDefaultImpl; - - protected Control createContents(Composite parent) { - Composite c = new Composite(parent, SWT.NONE); - c.setLayout(new GridLayout(2, false)); - c.setLayoutData(new GridData(GridData.FILL_BOTH)); - - Label lblLibs = new Label(c, SWT.NONE); - lblLibs.setText(Messages.JSFLibrariesPreferencePage_DefinedJSFLibraries); - GridData gd1 = new GridData(); - gd1.horizontalSpan = 2; - lblLibs.setLayoutData(gd1); - - tv = new TreeViewer(c, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - tvAdapter = new TreeViewerAdapter(); - tvLabelProvider = new TreeLabelProvider(); - tv.setContentProvider(tvAdapter); - tv.setLabelProvider(tvLabelProvider); - tv.addSelectionChangedListener(tvAdapter); - tv.addDoubleClickListener(tvAdapter); - tv.setComparator(tvAdapter); - tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); - tv.setInput(getJSFLibraries()); - - createButtons(c); - - return c; - } - - private void createButtons(Composite c){ - btnComp = new Composite(c, SWT.NONE); - GridLayout gl1 = new GridLayout(1, false); - gl1.marginHeight = 0; - gl1.marginWidth = 0; - btnComp.setLayout(gl1); - btnComp.setLayoutData(new GridData(GridData.END | GridData.VERTICAL_ALIGN_FILL)); - - btnNew = new Button(btnComp, SWT.NONE); - btnNew.setText(Messages.JSFLibrariesPreferencePage_New); - btnNew.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); - btnNew.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - openJSFLibraryEditDialog(null); - } - }); - - btnEdit = new Button(btnComp, SWT.NONE); - btnEdit.setText(Messages.JSFLibrariesPreferencePage_Edit); - btnEdit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); - btnEdit.setEnabled(false); - btnEdit.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - TreeItem[] element = tv.getTree().getSelection(); - if (element != null){ - openJSFLibraryEditDialog(element[0]); - } - - } - }); - - btnDelete = new Button(btnComp, SWT.NONE); - btnDelete.setText(Messages.JSFLibrariesPreferencePage_Remove); - btnDelete.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); - btnDelete.setEnabled(false); - btnDelete.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - boolean modified = false; - if (tv.getSelection() instanceof StructuredSelection){ - StructuredSelection objs = (StructuredSelection)tv.getSelection(); - if (objs != null){ - Iterator it = objs.iterator(); - while (it.hasNext()){ - JSFLibrary lib = (JSFLibrary)it.next(); - if (lib instanceof PluginProvidedJSFLibrary) - MessageDialog.openInformation( - getShell(), - Messages.JSFLibrariesPreferencePage_CannotRemovePluginProvidedTitle, - Messages.JSFLibrariesPreferencePage_CannotRemovePluginProvidedMessage); - - else { - JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().removeJSFLibrary(lib); - modified = true; - } - } - if (modified){ - JSFLibraryRegistryUtil.getInstance().saveJSFLibraryRegistry(); - tv.refresh(); - } - } - } - } - }); - - btnMakeDefaultImpl = new Button(btnComp, SWT.NONE); - btnMakeDefaultImpl.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_END)); - btnMakeDefaultImpl.setText(Messages.JSFLibrariesPreferencePage_MakeDefault); - btnMakeDefaultImpl.setVisible(false); - btnMakeDefaultImpl.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (tv.getSelection() instanceof StructuredSelection){ - StructuredSelection objs = (StructuredSelection)tv.getSelection(); - if (objs != null){ - if (objs.getFirstElement() instanceof JSFLibrary){ - JSFLibrary lib = (JSFLibrary)objs.getFirstElement(); - JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().setDefaultImplementation(lib); - } - JSFLibraryRegistryUtil.getInstance().saveJSFLibraryRegistry(); - tv.refresh(); - } - } - } - }); - - } - private Object getJSFLibraries() { - return JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getAllJSFLibraries(); - } - - public void init(IWorkbench workbench) { - wb = workbench; - setDescription(Messages.JSFLibrariesPreferencePage_Description); - noDefaultAndApplyButton(); - } - - /** - * Getter created only for JUnit tests. Should not be used otherwise. - * @return the TreeViewer of JSF Libraries - */ - public Viewer getLibraryViewer(){ - return tv; - } - - private class TreeViewerAdapter extends ViewerComparator implements ITreeContentProvider, ISelectionChangedListener, IDoubleClickListener { - private final Object[] NO_ELEMENTS= new Object[0]; - - // ------- ITreeContentProvider Interface ------------ - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // will never happen - } - - public void dispose() { - // do nothing - } - - public Object[] getElements(Object obj) { - return ((List)getJSFLibraries()).toArray(); - } - - public Object[] getChildren(Object element) { - if (element instanceof JSFLibrary) { - return ((JSFLibrary)element).getArchiveFiles().toArray(); - } - return NO_ELEMENTS; - } - - public Object getParent(Object element) { -// if (elements instanceof JSFLibrary) { -// return tvAdapter.getParent(tv.getTree().class, element); -// } - return null;//fParentElement; - } - - public boolean hasChildren(Object element) { - if (element instanceof JSFLibrary) { - return true; - } - return false; - } - - // ------- ISelectionChangedListener Interface ------------ - - public void selectionChanged(SelectionChangedEvent event) { - doListSelected(event); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent) - */ - public void doubleClick(DoubleClickEvent event) { - doDoubleClick(event); - } - - public int compare(Viewer viewer, Object e1, Object e2) { - if (e1 instanceof JSFLibrary && e2 instanceof JSFLibrary){ - JSFLibrary lib1 = (JSFLibrary)e1; - JSFLibrary lib2 = (JSFLibrary)e2; - - return getComparator().compare(lib1.getLabel(), lib2.getLabel()); - } - return super.compare(viewer, e1, e2); - } - - - } - - /** - * Respond to a list selection event - * - * @param event - */ - protected void doListSelected(SelectionChangedEvent event) { - updateButtonState(); - } - - /** - * Respond to a double click event by opening the edit dialog - * @param event - */ - protected void doDoubleClick(DoubleClickEvent event) { - openJSFLibraryEditDialog(tv.getTree().getSelection()[0]); - } - - private void updateButtonState() { - btnEdit.setEnabled(tv.getTree().getSelectionCount() == 1); - if (tv.getTree().getSelectionCount() == 1 && tv.getTree().getSelection()[0].getData() instanceof JSFLibrary){ - btnDelete.setEnabled(true); - btnMakeDefaultImpl.setVisible(false); - JSFLibrary lib = (JSFLibrary)tv.getTree().getSelection()[0].getData(); - btnMakeDefaultImpl.setVisible(lib.isImplementation()); - } else { - btnDelete.setEnabled(false); - btnMakeDefaultImpl.setVisible(false); - } - } - - private void openJSFLibraryEditDialog(Object element) { - if (isPluginProvidedJSFLibrary(element)){ - MessageDialog.openInformation( - getShell(), - Messages.JSFLibrariesPreferencePage_CannotModifyPluginProvidedTitle, - Messages.JSFLibrariesPreferencePage_CannotModifyPluginProvidedMessage); - return; - } - IWorkbenchWizard wizard = new JSFLibraryWizard(); - wizard.init(wb, getStructuredElement(element)); - WizardDialog dialog = new WizardDialog(wb.getActiveWorkbenchWindow().getShell(), wizard); - int ret = dialog.open(); - if (ret == Window.OK){ - tv.refresh(); - } - } - - private IStructuredSelection getStructuredElement(Object element) { - if (element instanceof TreeItem){ - Object item = ((TreeItem)element).getData(); - if (item instanceof ArchiveFile){ - JSFLibrary parent = ((ArchiveFile)item).getJSFLibrary(); - return new StructuredSelection(parent); - } else if (item instanceof JSFLibrary) { - return new StructuredSelection(item); - } - } - return null; - } - - private boolean isPluginProvidedJSFLibrary(Object treeElement){ - if (treeElement instanceof TreeItem){ - Object item = ((TreeItem)treeElement).getData(); - if (item instanceof PluginProvidedJSFLibrary){ - return true; - } else if (item instanceof ArchiveFile) { - return (((ArchiveFile)item).getJSFLibrary() instanceof PluginProvidedJSFLibrary); - } - } - return false; - } - - private static class TreeLabelProvider implements ILabelProvider { - private final Image libImg; - private final Image jarImg; - - TreeLabelProvider(){ - ImageDescriptor jarImgDesc = JSFUiPlugin.getImageDescriptor("obj16/jar_obj.gif"); //$NON-NLS-1$ - jarImg = jarImgDesc.createImage(); - ImageDescriptor libImgDesc = JSFUiPlugin.getImageDescriptor("obj16/library_obj.gif"); //$NON-NLS-1$ - libImg = libImgDesc.createImage(); - } - - public Image getImage(Object element) { - if (element instanceof JSFLibrary) - { - return libImg; - } - return jarImg; - } - - public String getText(Object element) { - StringBuffer labelBuf = new StringBuffer(); - if (element instanceof JSFLibrary) { - JSFLibrary lib = (JSFLibrary)element; - labelBuf.append(lib.getLabel()); - if (lib.isImplementation()) { - if (lib == JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getDefaultImplementation()) { - labelBuf.append(Messages.JSFLibrariesPreferencePage_DEFAULT_IMPL_DESC); - } else { - labelBuf.append(Messages.JSFLibrariesPreferencePage_IMPL_DESC); - } - } - } - if (element instanceof ArchiveFile) { - ArchiveFile jar = (ArchiveFile)element; - labelBuf.append(jar.getName()); - if (!jar.exists()) - labelBuf.append(Messages.JSFLibrariesPreferencePage_MISSING_DESC); - labelBuf.append(" - ").append(((ArchiveFile)element).getSourceLocation()); //$NON-NLS-1$ - } - return labelBuf.toString(); - } - - public void addListener(ILabelProviderListener listener) { - // no listeners supported - } - - public void dispose() { - if (libImg != null){ - libImg.dispose(); - } - if (jarImg != null){ - jarImg.dispose(); - } - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // no listeners supported - } - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryContainerWizardPage.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryContainerWizardPage.java deleted file mode 100644 index 950a4056b..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryContainerWizardPage.java +++ /dev/null @@ -1,579 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 2007 Oracle Corporation. - * 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: - * Gerry Kessler - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; -import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension; -import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension2; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -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.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.PluginProvidedJSFLibrary; -import org.eclipse.jst.jsf.core.jsfappconfig.JSFAppConfigUtils; -import org.eclipse.jst.jsf.core.jsflibraryconfiguration.JSFLibraryConfigurationHelper; -import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; -import org.eclipse.jst.jsf.ui.internal.Messages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -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.Label; -import org.eclipse.swt.widgets.Table; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWizard; -import org.eclipse.ui.PlatformUI; - -/** - * Provides a classpath container wizard page for JSF Libraries. - * - * @author Gerry Kessler - Oracle - */ -public class JSFLibraryContainerWizardPage extends WizardPage implements - IClasspathContainerPage, IClasspathContainerPageExtension, IClasspathContainerPageExtension2{ - - private CheckboxTableViewer lv; - private JSFLibrariesTableViewerAdapter lvAdapter; - private JSFLibrariesListLabelProvider lvLabelProvider; - - private boolean isJSFProject = false; - private IClasspathEntry containerEntry; - private IClasspathEntry[] currentEntries; - private Map _currentLibs; - private JSFLibrary currentLib; - - private boolean _projectHaveV1JSFLibraries; // = false; - private IProject _iproject; - - /** - * Zero arg constructor - */ - public JSFLibraryContainerWizardPage(){ - super(Messages.JSFLibraryContainerWizardPage_PageName); - setTitle(Messages.JSFLibraryContainerWizardPage_Title); - setDescription(Messages.JSFLibraryContainerWizardPage_Description); - // TODO: Replace with a custom image. - setImageDescriptor( JSFUiPlugin.getImageDescriptor("full/wizban/addlibrary_wiz.gif")); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension#initialize(org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathEntry[]) - */ - public void initialize(IJavaProject project, IClasspathEntry[] currentEntries_) { - this.currentEntries = currentEntries_; - - _iproject = project.getProject(); - this.isJSFProject = JSFAppConfigUtils.isValidJSFProject(_iproject); - if (this.isJSFProject) - { - _projectHaveV1JSFLibraries = - JSFLibraryRegistryUtil.doesProjectHaveV1JSFLibraries(_iproject); - } - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#finish() - */ - public boolean finish() { - boolean finish = true; - if (_projectHaveV1JSFLibraries) - { - // if the user doesn't want to confirm, back off on the change - // and let them decide if they want to hit cancel - finish = WarningMessageDialog. - openConfirm(getShell() - , Messages.JSFLibraryContainerWizardPage_V1Registry_Warning_DialogTitle - , Messages.JSFLibraryContainerWizardPage_V1Registry_Warning_DialogText); - - if (finish) - { - JSFLibraryRegistryUtil.removeV1JSFLibraryProperty(Collections.singletonList(_iproject)); - } - } - return finish; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension2#getNewContainers() - */ - public IClasspathEntry[] getNewContainers() { - IPath cp = new Path(JSFLibraryConfigurationHelper.JSF_LIBRARY_CP_CONTAINER_ID); - List res = new ArrayList(); - Object[] items = lv.getCheckedElements(); - for (int i=0;i<items.length;i++){ - JSFLibrary jsfLib = (JSFLibrary)items[i]; - if (getSelectedJSFLibariesForProject().get(jsfLib.getID()) == null){ - IPath path = cp.append(new Path(jsfLib.getID())); - IClasspathEntry entry = JavaCore.newContainerEntry(path); - // need to update wtp dependency in j2ee mod dependency ui - res.add(entry); - } - } - return (IClasspathEntry[])res.toArray(new IClasspathEntry[]{}); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.wizard.WizardPage#isPageComplete() - */ - public boolean isPageComplete() { - if (!isJSFProject) { - return false; - } - if (isEditReference() && ! selectionHasChanged()) - return false; - - return isValid(); - } - - private boolean isValid() { - return isCheckedItems() && getErrorMessage() == null; - } - - //to be used to know whether the selected library has changed when in "edit" mode - private boolean selectionHasChanged() { - JSFLibrary lib = getCurrentLibrarySelection(); - if (lib == null) - return false; - - return (getJSFLibraryForEdit(containerEntry) != lib) ; - - } - - private JSFLibrary getCurrentLibrarySelection() { - JSFLibrary lib = null; - StructuredSelection ssel = (StructuredSelection)lv.getSelection(); - if (ssel != null && !ssel.isEmpty()){ - lib = (JSFLibrary)ssel.getFirstElement(); - } - return lib; - } - - private boolean isCheckedItems() { - return lv.getCheckedElements().length > 0; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#getSelection() - */ - public IClasspathEntry getSelection() { - IClasspathEntry entry = null; - if (isEditReference()){ - if (lv.getCheckedElements().length == 0) - return containerEntry; - - JSFLibrary lib = (JSFLibrary)lv.getCheckedElements()[0]; - if (lib != null){ - if (lib == getJSFLibraryForEdit(containerEntry)) - { - return containerEntry; - } - IPath path = new Path(JSFLibraryConfigurationHelper.JSF_LIBRARY_CP_CONTAINER_ID).append(new Path(lib.getID())); - entry = JavaCore.newContainerEntry(path, containerEntry.getAccessRules(), containerEntry.getExtraAttributes(),containerEntry.isExported()); - } - } - return entry; - - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#setSelection(org.eclipse.jdt.core.IClasspathEntry) - */ - public void setSelection(IClasspathEntry containerEntry) { - //this is signalling that this is an "edit" - this.containerEntry = containerEntry; - } - - public void createControl(Composite parent) { - //Build UI to display JSF Lib components from registry - Composite c = new Composite(parent, SWT.NONE); - c.setLayout(new GridLayout(2, false)); - c.setLayoutData(new GridData(GridData.FILL_BOTH)); - - //disable wizard if this is not a valid JSF project - if (!isJSFProject){ - Label warning = new Label(c , SWT.NONE); - warning.setText(Messages.JSFLibraryContainerWizardPage_WarningNoJSFFacet); - setControl(c); - return; - } - - Label lblViewer = new Label(c, SWT.NONE); - lblViewer.setText(Messages.JSFLibraryContainerWizardPage_JSFLibraries); - GridData gd1 = new GridData(GridData.BEGINNING); - gd1.horizontalSpan = 2; - lblViewer.setLayoutData(gd1); - - lv = createTableViewer(c); - lv.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); - - lvAdapter = new JSFLibrariesTableViewerAdapter(); - lvLabelProvider = new JSFLibrariesListLabelProvider(); - lv.setContentProvider(lvAdapter); - lv.setLabelProvider(lvLabelProvider); - lv.addSelectionChangedListener(lvAdapter); - lv.addDoubleClickListener(lvAdapter); - lv.setComparator(lvAdapter); - - Composite buttons = new Composite(c, SWT.NONE); - buttons.setLayout(new GridLayout(1, false)); - buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL)); - - final Button addButton = new Button(buttons, SWT.NONE); - addButton.setText(Messages.JSFLibraryContainerWizardPage_Add); - addButton.setLayoutData(new GridData(GridData.END | GridData.VERTICAL_ALIGN_BEGINNING)); - addButton.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e){ - openJSFLibraryWizard(null); - } - }); - - final Button editButton = new Button(buttons, SWT.NONE); - editButton.setText(Messages.JSFLibraryContainerWizardPage_Edit); - editButton.setLayoutData(new GridData(GridData.END | GridData.VERTICAL_ALIGN_BEGINNING)); - editButton.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e){ - StructuredSelection sel = (StructuredSelection)lv.getSelection(); - if ((sel == null || sel.isEmpty()) && containerEntry != null){ - JSFLibrary jsfLib = getJSFLibraryForEdit(containerEntry); - sel = new StructuredSelection(jsfLib); - } - openJSFLibraryWizard(sel); - } - - }); - editButton.setVisible(false); - lv.addSelectionChangedListener(new ISelectionChangedListener(){ - public void selectionChanged(SelectionChangedEvent event) { - setEditButton(event.getSelection()); - } - - private void setEditButton(final ISelection selection) { - IStructuredSelection sel = (IStructuredSelection)selection; - editButton.setVisible(sel.size()==1); - if (sel.size() == 1){ - JSFLibrary lib = (JSFLibrary)sel.getFirstElement(); - boolean pp = lib instanceof PluginProvidedJSFLibrary; - editButton.setEnabled(! pp); - if (isEditReference()){ - lv.setAllChecked(false); - lv.setChecked(lib, true); - } - } - - } - }); - setControl(c); - - if (isEditReference()){ - JSFLibrary lib = getJSFLibraryForEdit(containerEntry); - lv.setInput(getAllUnselectedJSFLibrariesExceptReferencedLib(lib)); - selectAndCheckCurrentLib(lib); - setDescription(Messages.JSFLibraryContainerWizardPage_EditLibrary_DescriptionText); - } - else { - lv.setInput(getAllJSFLibraries()); - lv.setCheckedElements(getSelectedJSFLibariesForProject().values().toArray(new Object[0])); - } - } - - private void selectAndCheckCurrentLib(final JSFLibrary lib) { - if (lib != null){ - StructuredSelection ssel = new StructuredSelection(lib); - lv.setSelection(ssel); - lv.setChecked(lib, true); - } - } - - private Object getAllUnselectedJSFLibrariesExceptReferencedLib(JSFLibrary referenceLib) { - List allLibs = getAllJSFLibraries(); - Collection selLibs = getSelectedJSFLibariesForProject().values(); - for (Iterator it=selLibs.iterator();it.hasNext();){ - JSFLibrary aLib = (JSFLibrary)it.next(); - int i= allLibs.indexOf(aLib); - //remove from allLibs unless it is the selected reference - if (i >= 0 && ((referenceLib == null) || (aLib != null && ! aLib.getID().equals(referenceLib.getID())))){ - allLibs.remove(i); - } - } - return allLibs; - } - - private List getJSFLibraryEntries(IClasspathEntry[] entries) { - List jsfLibs = new ArrayList(); - for (int i=0;i<entries.length;i++){ - IClasspathEntry entry = entries[i]; - if (JSFLibraryConfigurationHelper.isJSFLibraryContainer(entry)){ - JSFLibrary lib = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry(). getJSFLibraryByID(getLibraryId(entry)); - if (lib != null){ - jsfLibs.add(lib); - } - } - } - - return jsfLibs; - } - - private String getLibraryId(IClasspathEntry entry) { - return entry.getPath().segment(1); - } - - private void openJSFLibraryWizard(IStructuredSelection element){ - IWorkbenchWizard wizard = new JSFLibraryWizard(); - IWorkbench wb = PlatformUI.getWorkbench(); - wizard.init(wb, element); - WizardDialog dialog = new WizardDialog(wb.getActiveWorkbenchWindow().getShell(), wizard); - int ret = dialog.open(); - if (ret == Window.OK){ - //FIXME: select returned object - if (containerEntry == null){ - lv.setInput(getAllJSFLibraries()); - } - else { - lv.setInput(getAllUnselectedJSFLibrariesExceptReferencedLib(getJSFLibraryForEdit(containerEntry))); - lv.refresh(true); - } - lv.refresh(); - } - } - - private CheckboxTableViewer createTableViewer(Composite parent) { - Table table= new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - table.setFont(parent.getFont()); - CheckboxTableViewer tableViewer= new CheckboxTableViewer(table); - tableViewer.addCheckStateListener(new ICheckStateListener() { - public void checkStateChanged(CheckStateChangedEvent e) { - if (! isEditReference()){ - //ensure that existing CP entries cannot be unchecked - if (getSelectedJSFLibariesForProject().get(((JSFLibrary)e.getElement()).getID()) != null){ - if (containerEntry == null) - e.getCheckable().setChecked(e.getElement(), true); - else - lv.setAllChecked(true); - } - } - else { - //select only one - lv.setAllChecked(false); - lv.setChecked(e.getElement(), true); - if (isEditReference()) - lv.setSelection(new StructuredSelection(e.getElement())); - } - validate(); - } - }); - return tableViewer; - } - - private Map getSelectedJSFLibariesForProject(){ - if (_currentLibs == null){ - List allLibs = getAllJSFLibraries(); - List curLibs = getJSFLibraryEntries(currentEntries); - _currentLibs = new HashMap(curLibs.size()); - for (Iterator it=curLibs.iterator();it.hasNext();){ - JSFLibrary lib = (JSFLibrary)it.next(); - int index = getIndex(allLibs, lib); - if (index >=0) - _currentLibs.put(lib.getID(), allLibs.get(index)); - } - - } - return _currentLibs; - } - - private List getAllJSFLibraries() { - List allLibs = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getAllJSFLibraries(); - - return allLibs; - } - - - private JSFLibrary getJSFLibraryForEdit( - IClasspathEntry containerEntry_) { - if (currentLib == null){ - String id = getLibraryId(containerEntry_); - currentLib = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibraryByID(id); - } - return currentLib; - - } - - private int getIndex(List libs, JSFLibrary lib) { - for (int i=0;i<libs.size();i++){ - if (lib.getID().equals(((JSFLibrary)libs.get(i)).getID())) - return i; - } - return -1; - } - - private class JSFLibrariesTableViewerAdapter extends ViewerComparator implements IStructuredContentProvider, ISelectionChangedListener, IDoubleClickListener { - - private Object input; - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - input = newInput; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() { - // do nothing - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object inputElement) { - return ((List)input).toArray(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - if (isEditReference()){ - setPageComplete(isPageComplete()); - } - - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent) - */ - public void doubleClick(DoubleClickEvent event) { - doDoubleClick(event); - } - - public int compare(Viewer viewer, Object e1, Object e2) { - JSFLibrary lib1 = (JSFLibrary)e1; - JSFLibrary lib2 = (JSFLibrary)e2; - - //sort first by in selection already and then by name - boolean lib1Sel = getSelectedJSFLibariesForProject().get(lib1.getID())!=null; - boolean lib2Sel = getSelectedJSFLibariesForProject().get(lib2.getID())!= null; - - if ((lib1Sel && lib2Sel) || (!lib1Sel && !lib2Sel) ){ - return getComparator().compare(lib1.getLabel(), lib2.getLabel()); - } - else if (lib1Sel) - return -1; - else - return 1; - } - } - - private static class JSFLibrariesListLabelProvider implements ILabelProvider{ - Image libImg; - public Image getImage(Object element) { - if (libImg == null){ - ImageDescriptor libImgDesc = JSFUiPlugin.getImageDescriptor("obj16/library_obj.gif"); //$NON-NLS-1$ - libImg = libImgDesc.createImage(); - } - return libImg; - } - - public String getText(Object element) { - if (element instanceof JSFLibrary) { - JSFLibrary lib = (JSFLibrary)element; - if (lib.isImplementation()) { - return lib.getLabel() + " " + Messages.JSFLibrariesPreferencePage_IMPL_DESC; //$NON-NLS-1$ - } - return lib.getLabel(); - } - return null; - } - - public void dispose() { - if (libImg != null) - libImg.dispose(); - } - - public void addListener(ILabelProviderListener listener) { - // no listener support - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // no listener support - } - } - - private void validate() { - setErrorMessage(null); - int implChosenCount = implSelectedCount(); - if (implChosenCount>1){ - setErrorMessage(Messages.JSFLibraryContainerWizardPage_ImplAlreadyPresent); - } - setPageComplete(isPageComplete()); - } - - - private boolean isEditReference() { - return (containerEntry != null); - } - - private int implSelectedCount() { - int count = 0; - for (int i=0;i<lv.getCheckedElements().length;i++){ - JSFLibrary lib = (JSFLibrary)lv.getCheckedElements()[i]; - if (lib.isImplementation()) - count++; - } - return count; - } - - private void doDoubleClick(DoubleClickEvent event) { - StructuredSelection ssel = (StructuredSelection)event.getSelection(); - if (ssel != null && - (! ((JSFLibrary)ssel.getFirstElement() instanceof PluginProvidedJSFLibrary))) - openJSFLibraryWizard((IStructuredSelection)event.getSelection()); - } - - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryEditControl.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryEditControl.java deleted file mode 100644 index c781571a8..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryEditControl.java +++ /dev/null @@ -1,499 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryFactory; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFVersion; -import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; -import org.eclipse.jst.jsf.ui.internal.Messages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -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.FileDialog; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -/** - * Common control for adding JSF library instances - */ -public class JSFLibraryEditControl extends Composite implements ModifyListener, SelectionListener -{ - private Text txtName; - private Label lblName; - private CCombo cboVersions; - private Label lblVersions; - private Button chkDeploy; - private Button chkImpl; - private Composite btnBar; - private Button btnAdd; - private Button btnRemove; - private TableViewer jars; - - private boolean initing = false; - - private JSFLibrary workingCopyLibrary; - - private String validationMsg; - private Set _listeners; - private int _isNew = -1;//use isNew() method.. not this variable directly - - /** - * @param workingCopyLibrary working copy of the JSF library - * @param parent parent SWT control - */ - public JSFLibraryEditControl(JSFLibrary workingCopyLibrary, Composite parent){ - super(parent, SWT.NONE); - this.workingCopyLibrary = workingCopyLibrary; - _listeners = new HashSet(1); - createControl(parent); - } - - /** - * @param listener - */ - public void addValidationListener(JSFLibraryValidationListener listener){ - removeValidationListener(listener); - _listeners.add(listener); - } - - /** - * @param listener - */ - public void removeValidationListener(JSFLibraryValidationListener listener){ - _listeners.remove(listener); - } - - /** - * @param parent - */ - public void createControl(Composite parent) { - initing = true; - -// this = new Composite(parent, SWT.NONE); - this.setLayout(new GridLayout(2, false)); - this.setLayoutData(new GridData(GridData.FILL_BOTH)); - - lblName = new Label(this, SWT.NONE); - lblName.setText(Messages.JSFLibraryWizard_LibraryName); - lblName.setLayoutData(new GridData(GridData.BEGINNING)); - - txtName = new Text(this, SWT.BORDER); - txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - txtName.addModifyListener(this); - - lblVersions = new Label(this, SWT.NONE); - lblVersions.setText(Messages.JSFLibraryWizard_VersionSupported); - - cboVersions = new CCombo(this, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER); - cboVersions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - cboVersions.addModifyListener(this); - - Group jarsComp = new Group(this, SWT.NONE); - jarsComp.setText(Messages.JSFLibraryWizard_LibraryJars); - GridLayout gl1 = new GridLayout(2, false); - jarsComp.setLayout(gl1); - GridData gd2 = new GridData(GridData.FILL_HORIZONTAL - | GridData.FILL_VERTICAL); - gd2.horizontalSpan = 2; - jarsComp.setLayoutData(gd2); - - createJarsViewer(jarsComp); - - createButtons(jarsComp); - - chkImpl = new Button(this, SWT.CHECK); - chkImpl.setText(Messages.JSFLibraryWizard_IsJSFImplementation); - GridData gd3 = new GridData(); - gd3.horizontalSpan = 2; - chkImpl.setLayoutData(gd3); - chkImpl.addSelectionListener(this); - - chkDeploy = new Button(this, SWT.CHECK); - chkDeploy.setText(Messages.JSFLibraryWizard_DeployJars); - GridData gd4 = new GridData(); - gd4.horizontalSpan = 2; - chkDeploy.setLayoutData(gd4); -// chkDeploy.addSelectionListener(this); - chkDeploy.setVisible(false); - - loadVersions(); - - if (!isNew()) { - txtName.setText(workingCopyLibrary.getName()); - if (workingCopyLibrary.getJSFVersion().getName().equals(JSFVersion.UNKNOWN_LITERAL.getName())) { - cboVersions.setText(Messages.JSFLibraryEditControl_ImplVersion_UNKNOWN); - } else { - cboVersions.setText(workingCopyLibrary.getJSFVersion().getName()); - } - chkDeploy.setSelection(workingCopyLibrary.isDeployed()); - chkImpl.setSelection(workingCopyLibrary.isImplementation()); - } - jars.setInput(workingCopyLibrary); - - initing = false; - - txtName.setFocus(); - } - - private void createJarsViewer(Group jarsComp) { - jars = new TableViewer(jarsComp, SWT.BORDER | SWT.MULTI); - jars.setContentProvider(new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { - if (inputElement instanceof JSFLibrary) - return ((JSFLibrary) inputElement).getArchiveFiles() - .toArray(); - return new Object[0]; - } - - public void dispose() { - // do nothing - } - - public void inputChanged(Viewer viewer, Object oldInput, - Object newInput) { - // won't happen - } - }); - jars.setLabelProvider(new ILabelProvider() { - private Image jarImg = null; - public Image getImage(Object element) { - if (jarImg == null){ - ImageDescriptor desc = JSFUiPlugin.getImageDescriptor("obj16/jar_obj.gif"); //$NON-NLS-1$ - jarImg = desc.createImage(); - } - return jarImg; - } - - public String getText(Object element) { - StringBuffer labelBuf = new StringBuffer(); - if (element instanceof ArchiveFile) { - ArchiveFile archive = (ArchiveFile) element; - labelBuf.append(archive.getName()); - if (!archive.exists()) - labelBuf.append(Messages.JSFLibrariesPreferencePage_MISSING_DESC); - labelBuf.append(" - ").append(archive.getPath()); //$NON-NLS-1$ - } - return labelBuf.toString(); - } - - public void addListener(ILabelProviderListener listener) { - // no listeners supported - } - - public void dispose() { - if (jarImg != null) - jarImg.dispose(); - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // no listeners supported - } - }); - - jars.addSelectionChangedListener(new ISelectionChangedListener(){ - public void selectionChanged(SelectionChangedEvent event){ - updateButtons(); - } - }); - - GridData gd = new GridData(GridData.FILL_BOTH); -// gd.widthHint = convertWidthInCharsToPixels(30); -// gd.heightHint = convertHeightInCharsToPixels(10); - jars.getControl().setLayoutData(gd); - } - - private void updateButtons() { - btnRemove.setEnabled(!((StructuredSelection)jars.getSelection()).isEmpty()); - // getButton(IDialogConstants.OK_ID).setEnabled(modified); - } - - private void createButtons(Composite c) { - btnBar = new Composite(c, SWT.NONE); - GridLayout gl = new GridLayout(1, false); - gl.marginHeight = 0; - gl.marginTop = 0; - gl.marginWidth = 0; - btnBar.setLayout(gl); - btnBar.setLayoutData(new GridData(GridData.END)); - - btnAdd = new Button(btnBar, SWT.NONE); - btnAdd.setText(Messages.JSFLibraryWizard_Add); - btnAdd.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_BEGINNING)); - btnAdd.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - String cur = null; - String[] chosenJars = openExtJarFileDialog(cur); - if (chosenJars != null) { - for (int i = 0; i < chosenJars.length; i++) { - String jar = chosenJars[i]; - if (!workingCopyLibrary.containsArchiveFile(jar)) { - ArchiveFile archive = JSFLibraryRegistryFactory.eINSTANCE - .createArchiveFile(); - archive.setSourceLocation(jar); - archive.setRelativeDestLocation("WEB-INF/lib"); //$NON-NLS-1$ - workingCopyLibrary.getArchiveFiles().add(archive); - } - } - jars.refresh(); - validate(); - } - } - }); - - btnRemove = new Button(btnBar, SWT.NONE); - btnRemove.setEnabled(false); - btnRemove.setText(Messages.JSFLibraryWizard_Remove); - btnRemove.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_BEGINNING)); - btnRemove.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (jars.getSelection() instanceof StructuredSelection){ - StructuredSelection objs = (StructuredSelection)jars.getSelection(); - if (objs != null){ - Iterator it = objs.iterator(); - while (it.hasNext()){ - Object obj = it.next(); - ArchiveFile jar = (ArchiveFile)obj; - workingCopyLibrary.getArchiveFiles().remove(jar); - } - } - jars.refresh(); - validate(); - } - } - }); - } - - private void loadVersions() { - cboVersions.removeAll(); - Iterator it = JSFVersion.VALUES.iterator(); - while (it.hasNext()) { - JSFVersion ver = (JSFVersion) it.next(); - if (ver.getName().equals(JSFVersion.UNKNOWN_LITERAL.getName())) { - cboVersions.add(Messages.JSFLibraryEditControl_ImplVersion_UNKNOWN); - } else { - cboVersions.add(ver.getName()); - } - } - } - - private String[] openExtJarFileDialog(String existing) { - String title = Messages.JSFLibraryWizard_ExtJarFileDialogTitle; - - FileDialog dialog = new FileDialog(getShell(), - existing == null ? SWT.MULTI : SWT.SINGLE); - dialog.setText(title); - dialog.setFilterExtensions(new String[] { "*.jar;*.zip" }); //$NON-NLS-1$ - // FIXME: remember and use last path chosen?? - String filterPath = ResourcesPlugin.getWorkspace().getRoot() - .getFullPath().toString(); - dialog.setFilterPath(filterPath); - // if (existing != null) { - // dialog.setFileName(existing.getPath().lastSegment()); - // } - - String res = dialog.open(); - if (res == null) { - return null; - } - String[] fileNames = dialog.getFileNames(); - String[] elems = new String[fileNames.length]; - IPath file = new Path(res); - IPath apath = file.removeLastSegments(1); - for (int i = 0; i < fileNames.length; i++) { - elems[i] = apath.append(fileNames[i]).toString(); - } - return elems; - } - - public void modifyText(ModifyEvent e) { - validate(); - updateButtons(); - } - - private void fireValidateEvent(final JSFLibraryValidationEvent jSFLibraryValidationEvent) { - new Runnable(){ - public void run() { - for (Iterator it=_listeners.iterator();it.hasNext();){ - JSFLibraryValidationListener listener = (JSFLibraryValidationListener)it.next(); - listener.notifyValidation(jSFLibraryValidationEvent); - } - } - }.run(); - } - - - public void widgetSelected(SelectionEvent e) { - validate(); - updateButtons(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // no handling for default selection - } - - private void validate() { - if (initing) - return; - validationMsg = null; -// setPageComplete(true); - if (!validateName() || !validateJars() || !validateVersion()) { -// setPageComplete(false); - } - fireValidateEvent(new JSFLibraryValidationEvent(validationMsg)); - } - - private boolean validateJars() { - if (workingCopyLibrary.getArchiveFiles().isEmpty()) { - validationMsg = Messages.JSFLibraryWizard_ValidateNoJars; - return false; - } - return true; - } - - private boolean validateVersion() { - //FIXME: why isn't selection indesx correct??? - // if (cboVersions.getSelectionIndex() < 0) { - // setErrorMessage("Choose the maximum JSF version supported if known."); - // return false; - // } - return true; - } - - private boolean validateName() { - if (txtName.getText() == null - || txtName.getText().trim().equals("")) { //$NON-NLS-1$ - validationMsg = Messages.JSFLibraryWizard_ValidateNoLibraryName; - return false; - } - String aName = txtName.getText().trim(); - if (isNew() || (!isNew() && !getCurrentLibraryName().equals(aName))) { - if (isNameInRegistry(JSFLibraryRegistryUtil.getInstance() - .getJSFLibraryRegistry().getAllJSFLibraries(), aName)) { - validationMsg = Messages.JSFLibraryWizard_ValidateExistingLibraryName; - return false; - } - } - return true; - } - - private boolean isNew() { - if (_isNew == -1){ - _isNew = workingCopyLibrary.getName() == null ? 1 : 0; - } - return _isNew == 1; - } - - private String getCurrentLibraryName() { - return workingCopyLibrary.getName(); - } - - private boolean isNameInRegistry(Collection c, String name) { - Iterator it = c.iterator(); - while (it.hasNext()) { - JSFLibrary lib = (JSFLibrary) it.next(); - if (lib.getName().equals(name)) { - return true; - } - } - return false; - } - - /** - * @return the trimmed name of the user input for jsf library name - */ - public String getJSFLibraryName() { - return txtName.getText().trim(); - } - - - /** - * @return the value of the user input for the isDeployed checkbox - */ - public boolean getIsDeployed() { - return chkDeploy.getSelection(); - } - - - /** - * @return the value of the user input for the isJSFImplementation checkbox - */ - public boolean getIsImplementation() { - return chkImpl.getSelection(); - } - - /** - * @return the jsf version selected in the version dropping - */ - public JSFVersion getJSFVersion() { - if (cboVersions.getSelectionIndex() >= 0) { - JSFVersion ver = (JSFVersion) JSFVersion.VALUES.get(cboVersions - .getSelectionIndex()); - return ver; - } - return JSFVersion.UNKNOWN_LITERAL; - } - - /** - * @param implsOnly - */ - public void setImplOnly(boolean implsOnly) { - if (implsOnly){ - chkImpl.setSelection(true); - chkImpl.setEnabled(false); - } - } - - /** - * @param nonImplsOnly - */ - public void setNonImplOnly(boolean nonImplsOnly) { - if (nonImplsOnly){ - chkImpl.setSelection(false); - chkImpl.setEnabled(false); - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationEvent.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationEvent.java deleted file mode 100644 index a869d0a01..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationEvent.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -import org.eclipse.core.runtime.IStatus; - -/** - * Validation event used by JSFLibraryControl to notify containers of updates - * - */ -public class JSFLibraryValidationEvent { - private String msg; - private int severity; - - /** - * Constructor - * @param msg - * @param severity - IStatus int value - */ - public JSFLibraryValidationEvent(String msg, int severity) { - this.msg = msg; - this.severity = severity; - } - - /** - * Constructs event with severity of IStatus.ERROR - * @param msg - */ - public JSFLibraryValidationEvent(String msg) { - this(msg, IStatus.ERROR); - } - - /** - * @return validation message - */ - public String getMessage(){ - return msg; - } - - /** - * @return IStatus int value - */ - public int getSeverity(){ - return severity; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationListener.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationListener.java deleted file mode 100644 index dbd6b0182..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationListener.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -/** - * Listeners of {@link JSFLibraryValidationEvent}s should implement - * - */ -public interface JSFLibraryValidationListener { - /** - * Callback - * @param e - */ - public void notifyValidation(JSFLibraryValidationEvent e); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizard.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizard.java deleted file mode 100644 index bf771b16e..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizard.java +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 Oracle Corporation. - * 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: - * Gerry Kessler - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialogWithToggle; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryFactory; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFVersion; -import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; -import org.eclipse.jst.jsf.ui.internal.Messages; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; - -/** - * Dialog for creating or editing a JSF Library or Implementation. - * <br> - * If the selection passed in init is not null then the item will be edit mode. - * - * @author Gerry Kessler - Oracle - */ -public class JSFLibraryWizard extends Wizard implements INewWizard { - - /** - * Implementation libaries to be included - */ - public final static int IMPLS = 1; - /** - * Non-Implementation libaries to be included - */ - public final static int NONIMPLS = 2; - - private JSFLibraryEditControl jsfLibraryEditControl; - - private boolean isNew = false; - private boolean modified = false; - - private JSFLibrary curLibrary; - private JSFLibrary workingCopyLibrary; - - private JSFLibraryWizardPage page; - - private boolean _impls; - private boolean _nonimpls; - - private List<IProject> _projectsWithV1JSFLibraries = new ArrayList<IProject>(); - - /** - * Constructor - * see IMPLS - * see NONIMPLS - * @param libTypes - */ - public JSFLibraryWizard(int libTypes) { - super(); - if ((libTypes & IMPLS) == IMPLS) - _impls = true; - - if ((libTypes & NONIMPLS) == NONIMPLS) - _nonimpls = true; - } - - - /** - * Constructor. List will include all JSF Libraries. - */ - public JSFLibraryWizard() { - super(); - _impls = true; - _nonimpls = true; - } - - private boolean isImplsOnly(){ - if (_impls && ! _nonimpls) - return true; - return false; - } - - private boolean isNonImplsOnly(){ - if (_nonimpls && ! _impls) - return true; - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) - */ - public void init(IWorkbench workbench, IStructuredSelection selection) - { - initV1LibrariesList(); - - if (selection != null - && selection.getFirstElement() instanceof JSFLibrary) { - curLibrary = (JSFLibrary) selection.getFirstElement(); - workingCopyLibrary = curLibrary.getWorkingCopy(); - } else { - isNew = true; - workingCopyLibrary = JSFLibraryRegistryFactory.eINSTANCE.createJSFLibrary(); - } - if (isImplsOnly()) { - setWindowTitle(Messages.JSFLibraryWizard_CreateImplementation); - } else { - setWindowTitle(isNew ? Messages.JSFLibraryWizard_CreateJSFLibrary : Messages.JSFLibraryWizard_EditJSFLibrary); - } - } - - private void initV1LibrariesList() - { - final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - - // loop through the workspace and look for projects that are still using the V1 way - // of doing JSF libraries - for (int i = 0; i < projects.length; i++) - { - final IProject project = projects[i]; - if (JSFLibraryRegistryUtil.doesProjectHaveV1JSFLibraries(project)) - { - _projectsWithV1JSFLibraries.add(project); - } - } - } - - /** - * Updates the JSF Library instance with the values from the working copy and - * persists the registry. - * - * If editing a library reference, referencing java models will be updated. - * - * @see org.eclipse.jface.wizard.Wizard#performFinish() - */ - public boolean performFinish() - { - // on init, if we detected any projects with old library - // refs, we need to warn the user - if (!isNew && // can ignore new libraries, since old projects can't possibly have dependencies on them - _projectsWithV1JSFLibraries.size() > 0) - { - String projectNames = ""; //$NON-NLS-1$ - for (Iterator<IProject> it = _projectsWithV1JSFLibraries.iterator(); it.hasNext();) - { - IProject project = it.next(); - projectNames += project.getName() + ","; //$NON-NLS-1$ - } - // trim trailing comma - if (projectNames.length() > 0) - { - projectNames = projectNames.substring(0, projectNames.length()-1); - } - - final String messageText = MessageFormat.format(Messages.JSFLibraryWizard_V1JSFLibrary_DialogMessage, - new Object[] {projectNames}); - MessageDialogWithToggle dialog = - WarningMessageDialogWithToggle.openOkCancelConfirm - (getShell(), Messages.JSFLibraryWizard_V1JSFLibrary_DialogTitle, messageText, Messages.JSFLibraryWizard_JSFLibraryWizard_DontShowThisAgain_CheckBoxLabel, false, null, null); - if (dialog.getReturnCode() != IDialogConstants.OK_ID) - { - // abort if the user doesn't really want to commit this change - return false; - } - - // if user accepted and asked not be warned again, clear the - // the project properties. - if (dialog.getToggleState()) - { - JSFLibraryRegistryUtil.removeV1JSFLibraryProperty(_projectsWithV1JSFLibraries); - } - } - - final String name = jsfLibraryEditControl.getJSFLibraryName(); - final boolean isDeployed = jsfLibraryEditControl.getIsDeployed(); - final boolean isImplementation = jsfLibraryEditControl.getIsImplementation(); - final JSFVersion version = jsfLibraryEditControl.getJSFVersion(); - - workingCopyLibrary.setName(name); - workingCopyLibrary.setDeployed(isDeployed); - workingCopyLibrary.setImplementation(isImplementation); - workingCopyLibrary.setJSFVersion(version); - - final String originalID = curLibrary != null ? curLibrary.getID() :workingCopyLibrary.getID(); - - if (isNew){ - JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().addJSFLibrary(workingCopyLibrary); - } - else { - curLibrary.updateValues(workingCopyLibrary); - try { - JSFLibraryRegistryUtil.rebindClasspathContainerEntries(originalID, workingCopyLibrary.getID(), null); - } catch (JavaModelException e) { - JSFUiPlugin.log(IStatus.ERROR, "Exception while updating JSF Library containers", e); //$NON-NLS-1$ - } - } - JSFLibraryRegistryUtil.getInstance().saveJSFLibraryRegistry(); - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.wizard.Wizard#addPages() - */ - public void addPages() { - page = new JSFLibraryWizardPage(Messages.JSFLibraryWizard_JSFLibrary); - super.addPage(page); - page.setWizard(this); - } - - /** - * @return the JSFLibrary being modified by this wizard - */ - public JSFLibrary getJSFLibrary() { - return workingCopyLibrary; - } - - private class JSFLibraryWizardPage extends WizardPage { - - /** - * @param pageName - */ - protected JSFLibraryWizardPage(String pageName) { - super(pageName); - setDescription(isImplsOnly() - ? Messages.JSFLibraryWizard_IMPLS_ONLY_DESC - : Messages.JSFLibraryWizard_DESCRIPTION); - setTitle(Messages.JSFLibraryWizard_JSFLibrary); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.wizard.WizardPage#isPageComplete() - */ - public boolean isPageComplete() { - if (modified == false) { - return false; - } - return super.isPageComplete(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) - */ - public void createControl(Composite parent) { - initializeDialogUnits(parent); - - jsfLibraryEditControl = new JSFLibraryEditControl(workingCopyLibrary, parent); - jsfLibraryEditControl.setImplOnly(isImplsOnly()); - jsfLibraryEditControl.setNonImplOnly(isNonImplsOnly()); - jsfLibraryEditControl.setLayout(new GridLayout(2, false)); - jsfLibraryEditControl.setLayoutData(new GridData(GridData.FILL_BOTH)); - - jsfLibraryEditControl.addValidationListener(new JSFLibraryValidationListener(){ - public void notifyValidation(JSFLibraryValidationEvent e) { - setErrorMessage(e.getMessage()); - modified = true; - setPageComplete(getErrorMessage()==null); - } - }); - - setControl(jsfLibraryEditControl); - setPageComplete(false); - } - - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialog.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialog.java deleted file mode 100644 index ad3b13608..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialog.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleAdapter; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Customized warning dialog for JSF Library Upgrade warnings. - * - * @author cbateman - * - */ -class WarningMessageDialog extends MessageDialog -{ - private Text _messageLabel; - - /** - * @param parent - * @param title - * @param message - * @return true if the user hit OK - * - * Overriden to set the default button to CANCEL and use this dialog. - */ - public static boolean openConfirm(Shell parent, String title, String message) { - MessageDialog dialog = new WarningMessageDialog(parent, title, null, // accept - // the - // default - // window - // icon - message, QUESTION, new String[] { IDialogConstants.OK_LABEL, - IDialogConstants.CANCEL_LABEL }, 1); // CANCEL is the - // default - return dialog.open() == 0; - } - - WarningMessageDialog(Shell parentShell, String dialogTitle, - Image dialogTitleImage, String dialogMessage, int dialogImageType, - String[] dialogButtonLabels, int defaultIndex) { - super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, - dialogImageType, dialogButtonLabels, defaultIndex); - } - - @Override - protected Control createMessageArea(Composite composite) - { - // create composite - // create image - Image image = getImage(); - if (image != null) { - imageLabel = new Label(composite, SWT.NULL); - image.setBackground(imageLabel.getBackground()); - imageLabel.setImage(image); - addAccessibleListeners(imageLabel, image); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING) - .applyTo(imageLabel); - } - // create message - if (message != null) { - _messageLabel = new Text(composite, getMessageLabelStyle()|SWT.READ_ONLY); - _messageLabel.setText(message); - GridDataFactory - .fillDefaults() - .align(SWT.FILL, SWT.BEGINNING) - .grab(true, false) - .hint( - convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), - SWT.DEFAULT).applyTo(_messageLabel); - } - return composite; - } - - /** - * NOTE: copied from IconAndMessageDialog - * Add an accessible listener to the label if it can be inferred from the - * image. - * - * @param label - * @param image - */ - private void addAccessibleListeners(Label label, final Image image) { - label.getAccessible().addAccessibleListener(new AccessibleAdapter() { - public void getName(AccessibleEvent event) { - final String accessibleMessage = getAccessibleMessageFor(image); - if (accessibleMessage == null) { - return; - } - event.result = accessibleMessage; - } - }); - } - - /** - * NOTE: copied from IconAndMessageDialog - * @param image - * @return an accesible string - */ - private String getAccessibleMessageFor(Image image) { - if (image.equals(getErrorImage())) { - return JFaceResources.getString("error");//$NON-NLS-1$ - } - - if (image.equals(getWarningImage())) { - return JFaceResources.getString("warning");//$NON-NLS-1$ - } - - if (image.equals(getInfoImage())) { - return JFaceResources.getString("info");//$NON-NLS-1$ - } - - if (image.equals(getQuestionImage())) { - return JFaceResources.getString("question"); //$NON-NLS-1$ - } - - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialogWithToggle.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialogWithToggle.java deleted file mode 100644 index 834889d3e..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialogWithToggle.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.classpath; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialogWithToggle; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.AccessibleAdapter; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * Customized warning dialog for JSF Library Upgrade warnings. - * - * @author cbateman - * - */ -class WarningMessageDialogWithToggle extends MessageDialogWithToggle -{ - private Text _messageLabel; - - /** - * @param parent - * @param title - * @param message - * @param toggleMessage - * @param toggleState - * @param store - * @param key - * @return the dialog. - * - * Overriden to make default button CANCEL and use this dialog - */ - public static MessageDialogWithToggle openOkCancelConfirm(Shell parent, - String title, String message, String toggleMessage, - boolean toggleState, IPreferenceStore store, String key) { - MessageDialogWithToggle dialog = new WarningMessageDialogWithToggle(parent, - title, null, // accept the default window icon - message, QUESTION, new String[] { IDialogConstants.OK_LABEL, - IDialogConstants.CANCEL_LABEL }, 1, // CANCEL is the default - toggleMessage, toggleState); - dialog.open(); - return dialog; - } - - WarningMessageDialogWithToggle(Shell parentShell, String dialogTitle, - Image image, String message, int dialogImageType, - String[] dialogButtonLabels, int defaultIndex, - String toggleMessage, boolean toggleState) { - super(parentShell, dialogTitle, image, message, dialogImageType, - dialogButtonLabels, defaultIndex, toggleMessage, toggleState); - } - - @Override - protected Control createMessageArea(Composite composite) - { - // create composite - // create image - Image image = getImage(); - if (image != null) { - imageLabel = new Label(composite, SWT.NULL); - image.setBackground(imageLabel.getBackground()); - imageLabel.setImage(image); - addAccessibleListeners(imageLabel, image); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING) - .applyTo(imageLabel); - } - // create message - if (message != null) { - _messageLabel = new Text(composite, getMessageLabelStyle()|SWT.READ_ONLY); - _messageLabel.setText(message); - GridDataFactory - .fillDefaults() - .align(SWT.FILL, SWT.BEGINNING) - .grab(true, false) - .hint( - convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), - SWT.DEFAULT).applyTo(_messageLabel); - } - return composite; - } - - /** - * NOTE: copied from IconAndMessageDialog - * Add an accessible listener to the label if it can be inferred from the - * image. - * - * @param label - * @param image - */ - private void addAccessibleListeners(Label label, final Image image) { - label.getAccessible().addAccessibleListener(new AccessibleAdapter() { - public void getName(AccessibleEvent event) { - final String accessibleMessage = getAccessibleMessageFor(image); - if (accessibleMessage == null) { - return; - } - event.result = accessibleMessage; - } - }); - } - - /** - * NOTE: copied from IconAndMessageDialog - * @param image - * @return an accesible string - */ - private String getAccessibleMessageFor(Image image) { - if (image.equals(getErrorImage())) { - return JFaceResources.getString("error");//$NON-NLS-1$ - } - - if (image.equals(getWarningImage())) { - return JFaceResources.getString("warning");//$NON-NLS-1$ - } - - if (image.equals(getInfoImage())) { - return JFaceResources.getString("info");//$NON-NLS-1$ - } - - if (image.equals(getQuestionImage())) { - return JFaceResources.getString("question"); //$NON-NLS-1$ - } - - return null; - } - -} |