diff options
author | Matthew Piggott | 2011-04-15 19:00:53 +0000 |
---|---|---|
committer | Matthew Piggott | 2011-04-15 19:03:24 +0000 |
commit | 7a7ea5a6d6378cce9700443e7f506b22c2787e20 (patch) | |
tree | f6d8b7af1ef386fc657d61dddbd53d8f279f96c1 /org.eclipse.m2e.core.ui/src | |
parent | cfc9d18fb6459472703ee574e6d5a1e0e6f5effe (diff) | |
download | m2e-core-7a7ea5a6d6378cce9700443e7f506b22c2787e20.tar.gz m2e-core-7a7ea5a6d6378cce9700443e7f506b22c2787e20.tar.xz m2e-core-7a7ea5a6d6378cce9700443e7f506b22c2787e20.zip |
Initial UpdateDependenciesDialog
Diffstat (limited to 'org.eclipse.m2e.core.ui/src')
-rw-r--r-- | org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenImages.java | 196 | ||||
-rw-r--r-- | org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/UpdateDepenciesDialog.java | 255 |
2 files changed, 345 insertions, 106 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenImages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenImages.java index ff3443cf..7ce8cb54 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenImages.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/MavenImages.java @@ -18,7 +18,6 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.jface.viewers.DecorationOverlayIcon; import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -31,103 +30,107 @@ public class MavenImages { // object images public static final Image IMG_CLEAR = createImage("clear.gif"); //$NON-NLS-1$ - + public static final Image IMG_CLEAR_DISABLED = createImage("clear_disabled.gif"); //$NON-NLS-1$ public static final String PATH_JAR = "jar_obj.gif"; //$NON-NLS-1$ - + public static final String PATH_PROJECT = "project_obj.gif"; //$NON-NLS-1$ - public static final Image IMG_JAR = createImage(PATH_JAR); - + public static final Image IMG_JAR = createImage(PATH_JAR); + public static final String PATH_LOCK = "lock_ovr.gif"; //$NON-NLS-1$ - + public static final String PATH_VERSION = "jar_version.gif"; //$NON-NLS-1$ - + public static final Image IMG_VERSION = createImage(PATH_VERSION); - + public static final String PATH_VERSION_SRC = "jar_src_version.gif"; //$NON-NLS-1$ - - public static final Image IMG_VERSION_SRC = createImage(PATH_VERSION_SRC); - + + public static final Image IMG_VERSION_SRC = createImage(PATH_VERSION_SRC); + public static final Image IMG_JAVA = createImage("java_obj.gif"); //$NON-NLS-1$ - + public static final Image IMG_JAVA_SRC = createImage("java_src_obj.gif"); //$NON-NLS-1$ - + // public static final Image IMG_M2 = createImage("m2.gif"); - + public static final Image IMG_LAUNCH_MAIN = createImage("main_tab.gif"); //$NON-NLS-1$ - + public static final Image IMG_INDEX = createImage("maven_index.gif"); //$NON-NLS-1$ - + public static final Image IMG_INDEXES = createImage("maven_indexes.gif"); //$NON-NLS-1$ - + public static final Image IMG_MAVEN_JAR = createImage("mjar.gif"); //$NON-NLS-1$ - + // public static final Image IMG_JAR = createImage("mlabel.gif"); - + //public static final Image IMG_NEW_POM = createImage("new_m2_pom.gif"); //$NON-NLS-1$ - + public static final Image IMG_NEW_PROJECT = createImage("new_m2_project.gif"); //$NON-NLS-1$ - + public static final Image IMG_OPEN_POM = createImage("open_pom.gif"); //$NON-NLS-1$ - + public static final Image IMG_PASSED = createImage("passed.png"); //$NON-NLS-1$ public static final Image IMG_POM = createImage("pom_obj.gif"); //$NON-NLS-1$ - + public static final Image IMG_UPD_DEPENDENCIES = createImage("update_dependencies.gif"); //$NON-NLS-1$ - + public static final Image IMG_UPD_SOURCES = createImage("update_source_folders.gif"); //$NON-NLS-1$ - + public static final Image IMG_WEB = createImage("web.gif"); //$NON-NLS-1$ - + public static final Image IMG_ERROR = createImage("error_st_obj.gif"); //$NON-NLS-1$ - + // wizard images - + public static final ImageDescriptor WIZ_IMPORT_WIZ = createDescriptor("import_project.png"); //$NON-NLS-1$ public static final ImageDescriptor WIZ_NEW_PROJECT = createDescriptor("new_m2_project_wizard.gif"); //$NON-NLS-1$ - + // descriptors - + public static final ImageDescriptor M2 = createDescriptor("m2.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor DEBUG = createDescriptor("debug.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor ADD_INDEX = createDescriptor("add_index.gif"); //$NON-NLS-1$ public static final ImageDescriptor CLOSE = createDescriptor("close.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor COPY = createDescriptor("copy.gif"); //$NON-NLS-1$ public static final ImageDescriptor COLLAPSE_ALL = createDescriptor("collapseall.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor EXPAND_ALL = createDescriptor("expandall.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor NEW_POM = createDescriptor("new_m2_pom.gif"); //$NON-NLS-1$ public static final ImageDescriptor REFRESH = createDescriptor("refresh.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor UPD_INDEX = createDescriptor("update_index.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor REBUILD_INDEX = createDescriptor("rebuild_index.gif"); //$NON-NLS-1$ public static final ImageDescriptor POM = createDescriptor("pom_obj.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor IMPORT_PROJECT = createDescriptor("import_m2_project.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor SHOW_CONSOLE_ERR = createDescriptor("stderr.gif"); //$NON-NLS-1$ - + public static final ImageDescriptor SHOW_CONSOLE_OUT = createDescriptor("stdout.gif"); //$NON-NLS-1$ - + + public static final ImageDescriptor MAVEN_OVERLAY = createDescriptor("mlabel.gif"); //$NON-NLS-1$ + + public static final String MVN_PROJECT = "project-mlabel.gif"; //$NON-NLS-1$ + private static ImageDescriptor createDescriptor(String key) { try { ImageRegistry imageRegistry = getImageRegistry(); if(imageRegistry != null) { ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(key); - if(imageDescriptor==null) { + if(imageDescriptor == null) { imageDescriptor = doCreateDescriptor(key); imageRegistry.put(key, imageDescriptor); } @@ -153,77 +156,58 @@ public class MavenImages { private static ImageDescriptor doCreateDescriptor(String image) { return AbstractUIPlugin.imageDescriptorFromPlugin(M2EUIPluginActivator.PLUGIN_ID, "icons/" + image); //$NON-NLS-1$ } - - - - private static ImageDescriptor createImageDescriptor( String key, ImageData imageData ) - { - try - { - ImageRegistry imageRegistry = getImageRegistry(); - if ( imageRegistry != null ) - { - ImageDescriptor imageDescriptor = imageRegistry.getDescriptor( key ); - if ( imageDescriptor != null ) - { - imageRegistry.remove( key ); - } - { - imageDescriptor = ImageDescriptor.createFromImageData( imageData ); - imageRegistry.put( key, imageDescriptor ); - } - return imageDescriptor; - } - } - catch ( Exception ex ) - { - log.error(key, ex); - } - return null; - } - private static ImageDescriptor getOverlayImageDescriptor( String basekey, String overlaykey, int quadrant ) - { - String key = basekey + overlaykey; - try - { - ImageRegistry imageRegistry = getImageRegistry(); - if ( imageRegistry != null ) - { - ImageDescriptor imageDescriptor = imageRegistry.getDescriptor( key ); - if ( imageDescriptor == null ) - { - ImageDescriptor base = createDescriptor( basekey ); - ImageDescriptor overlay = createDescriptor( overlaykey ); - if ( base == null || overlay == null ) - { - log.error( "cannot construct overlay image descriptor for " + basekey + " " + overlaykey ); - return null; - } - imageDescriptor = createOverlayDescriptor( base, overlay, quadrant ); - imageRegistry.put( key, imageDescriptor ); - } - return imageDescriptor; + private static ImageDescriptor getOverlayImageDescriptor(String basekey, String overlaykey, int quadrant) { + String key = basekey + overlaykey; + try { + ImageRegistry imageRegistry = getImageRegistry(); + if(imageRegistry != null) { + ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(key); + if(imageDescriptor == null) { + ImageDescriptor base = createDescriptor(basekey); + ImageDescriptor overlay = createDescriptor(overlaykey); + if(base == null || overlay == null) { + log.error("cannot construct overlay image descriptor for " + basekey + " " + overlaykey); //$NON-NLS-1$ //$NON-NLS-2$ + return null; } + imageDescriptor = createOverlayDescriptor(base, overlay, quadrant); + imageRegistry.put(key, imageDescriptor); + } + return imageDescriptor; } - catch ( Exception ex ) - { - log.error(key, ex); - } - return null; + } catch(Exception ex) { + log.error(key, ex); + } + return null; } - public static Image getOverlayImage( String base, String overlay, int quadrant ) - { - getOverlayImageDescriptor( base, overlay, quadrant ); - ImageRegistry imageRegistry = getImageRegistry(); - return imageRegistry == null ? null : imageRegistry.get( base + overlay ); + public static Image getOverlayImage(String base, String overlay, int quadrant) { + getOverlayImageDescriptor(base, overlay, quadrant); + ImageRegistry imageRegistry = getImageRegistry(); + return imageRegistry == null ? null : imageRegistry.get(base + overlay); } + public static Image createOverlayImage(String key, Image base, ImageDescriptor overlay, int quadrant) { + ImageRegistry registry = getImageRegistry(); + if(registry != null) { + Image image = registry.get(key); + if(image == null) { + ImageDescriptor descriptor = registry.getDescriptor(key); + if(descriptor == null) { + registry.put(key, createOverlayDescriptor(base, overlay, quadrant)); + } + image = registry.get(key); + } + return image; + } + return null; + } - private static ImageDescriptor createOverlayDescriptor( ImageDescriptor base, ImageDescriptor overlay, int quadrant ) - { - return new DecorationOverlayIcon( base.createImage(), overlay, quadrant ); + private static ImageDescriptor createOverlayDescriptor(ImageDescriptor base, ImageDescriptor overlay, int quadrant) { + return new DecorationOverlayIcon(base.createImage(), overlay, quadrant); } -} + private static ImageDescriptor createOverlayDescriptor(Image base, ImageDescriptor overlay, int quadrant) { + return new DecorationOverlayIcon(base, overlay, quadrant); + } +}
\ No newline at end of file diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/UpdateDepenciesDialog.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/UpdateDepenciesDialog.java new file mode 100644 index 00000000..f1fc6e32 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/dialogs/UpdateDepenciesDialog.java @@ -0,0 +1,255 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * 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: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.m2e.core.ui.internal.dialogs; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +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.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; + +import org.apache.maven.project.MavenProject; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.internal.M2EUtils; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.ui.internal.MavenImages; + +/** + * UpdateDep + * + * @author matthew + */ +public class UpdateDepenciesDialog extends TitleAreaDialog { + private static final Logger log = LoggerFactory.getLogger(UpdateDepenciesDialog.class); + + private CheckboxTableViewer codebaseViewer; + + private Collection<IProject> projects; + + private Button checkSnapshots; + + private Button updateRemote; + + private IProject[] selectedProjects; + + private boolean isCheckSnapshots = false; + + private boolean isUpdateRemote = false; + + /** + * Create the dialog. + * @param parentShell + */ + public UpdateDepenciesDialog(Shell parentShell) { + super(parentShell); + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Update Maven Dependencies"); + } + + /** + * Create contents of the dialog. + * @param parent + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite area = (Composite) super.createDialogArea(parent); + Composite container = new Composite(area, SWT.NONE); + container.setLayout(new GridLayout(2, false)); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label lblAvailable = new Label(container, SWT.NONE); + lblAvailable.setText("Available Maven Codebases"); + lblAvailable.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1)); + + codebaseViewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER); + codebaseViewer.setContentProvider(new IStructuredContentProvider() { + + public Object[] getElements(Object inputElement) { + if(inputElement instanceof Collection) { + return ((Collection) inputElement).toArray(); + } + return null; + } + + public void dispose() { + // TODO Auto-generated method dispose + + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // TODO Auto-generated method inputChanged + + } + }); + codebaseViewer.setLabelProvider(new LabelProvider() { + public Image getImage(Object element) { + return MavenImages.createOverlayImage(MavenImages.MVN_PROJECT, PlatformUI.getWorkbench().getSharedImages() + .getImage(IDE.SharedImages.IMG_OBJ_PROJECT), MavenImages.MAVEN_OVERLAY, IDecoration.TOP_LEFT); + } + + public String getText(Object element) { + return element instanceof IProject ? ((IProject) element).getName() : ""; //$NON-NLS-1$ + } + }); + projects = getMavenCodebases(new NullProgressMonitor()); + codebaseViewer.setInput(projects); + + Table table = codebaseViewer.getTable(); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2); + gd.heightHint = 300; + gd.widthHint = 300; + table.setLayoutData(gd); + + Button selectAllBtn = new Button(container, SWT.NONE); + selectAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + selectAllBtn.setText("Select All"); + selectAllBtn.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + codebaseViewer.setAllChecked(true); + } + + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + + Button deselectAllBtn = new Button(container, SWT.NONE); + deselectAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); + deselectAllBtn.setText("Deselect All"); + deselectAllBtn.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + codebaseViewer.setAllChecked(false); + } + + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + + checkSnapshots = new Button(container, SWT.CHECK); + checkSnapshots.setText("Forces a check for updated releases and snapshots on remote"); + checkSnapshots.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1)); + + updateRemote = new Button(container, SWT.CHECK); + updateRemote.setText("Do not automatically update dependencies from remote"); + updateRemote.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1)); + + setTitle("Update Maven Dependencies"); + setMessage("Select Maven codebases to update dependencies"); + + return area; + } + + /** + * Create contents of the button bar. + * @param parent + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + + protected void okPressed() { + ISelection selection = codebaseViewer.getSelection(); + if(selection instanceof IStructuredSelection) { + Object[] obj = ((IStructuredSelection) selection).toArray(); + IProject[] projects = new IProject[obj.length]; + for(int i = 0; i < obj.length; i++ ) { + projects[i] = (IProject) obj[i]; + } + selectedProjects = projects; + } + super.okPressed(); + } + + /** + * Return the initial size of the dialog. + */ +// @Override +// protected Point getInitialSize() { +// return new Point(450, 450); +// } + + public Collection<IProject> getMavenCodebases(IProgressMonitor monitor) { + Set<IProject> projects = new HashSet<IProject>(); + SubMonitor mon = SubMonitor.convert(monitor, MavenPlugin.getMavenProjectRegistry().getProjects().length); + try { + for(IMavenProjectFacade facade : MavenPlugin.getMavenProjectRegistry().getProjects()) { + try { + MavenProject root = facade.getMavenProject(mon.newChild(1)); + while(root.getParent() != null && root.getParent().getFile() != null) { + root = root.getParent(); + } + if(root.getFile() != null) { + IFile pomFile = M2EUtils.getPomFile(root); + if(pomFile != null) { + projects.add(pomFile.getProject()); + } + } + } catch(CoreException ex) { + log.error(ex.getMessage(), ex); + } + } + } finally { + mon.done(); + } + return projects; + } + + public IProject[] getSelectedProjects() { + return selectedProjects; + } + + public boolean isCheckSnapshots() { + return isCheckSnapshots; + } + + public boolean isUpdateRemote() { + return isUpdateRemote; + } +} |