diff options
author | Steven Spungin | 2014-06-06 14:24:04 +0000 |
---|---|---|
committer | Steven Spungin | 2014-06-06 17:09:59 +0000 |
commit | 6b0221ba440d61fd94df2cb038f803371e12450c (patch) | |
tree | 46ebdb408f1986b1157c5b8d58fb13d7f702f698 | |
parent | e49ac56a517d41657bf6e7394585b0c802e2d256 (diff) | |
download | org.eclipse.e4.tools-6b0221ba440d61fd94df2cb038f803371e12450c.tar.gz org.eclipse.e4.tools-6b0221ba440d61fd94df2cb038f803371e12450c.tar.xz org.eclipse.e4.tools-6b0221ba440d61fd94df2cb038f803371e12450c.zip |
Bug 436847 - [nonreferenced resource dialog] null pointer used whenI20140611-2200I20140611-0900I20140610-2200
calculating url
Bug 436848 - [nonreferenced resource dialog] Dialog should be a wizard
Bug 436849 - [find contributions dialog] Dispose error if closing while
provider is indexing
Change-Id: Ib958a4aa065bc31ce27a15fb700d95af40fa1c3a
Signed-off-by: Steven Spungin <steven@spungin.tv>
8 files changed, 1080 insertions, 35 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java index ff07eea5..5c84961d 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/ContributionClassDialog.java @@ -8,19 +8,18 @@ * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation * Lars Vogel <lars.vogel@gmail.com> - Enhancements - * Steven Spungin <steven@spungin.tv> - Bug 424730 + * Steven Spungin <steven@spungin.tv> - Bug 424730, Bug 436847 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs; -import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformClassContributionCollector; -import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformContributionCollector; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData; import org.eclipse.e4.tools.emf.ui.internal.Messages; import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformClassContributionCollector; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformContributionCollector; import org.eclipse.e4.ui.model.application.MApplicationElement; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.ecore.EStructuralFeature; @@ -64,6 +63,10 @@ public class ContributionClassDialog extends FilteredContributionDialog { ContributionDataFile cdf = new ContributionDataFile(cd); IFile file = checkResourceAccessible(cdf, cd.installLocation); if (file != null) { + if (file instanceof ContributionDataFile) { + cdf = (ContributionDataFile) file; + cd = cdf.getContributionData(); + } String uri = "bundleclass://" + cd.bundleName + "/" + cd.className; //$NON-NLS-1$ //$NON-NLS-2$ Command cmd = SetCommand.create(editingDomain, contribution, feature, uri); if (cmd.canExecute()) { diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java index 37664453..3d2ce7f1 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FilteredContributionDialog.java @@ -48,6 +48,7 @@ import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatfor import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformContributionCollector; import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformIconContributionCollector; import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.NonReferencedResourceDialog; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.NonReferencedResourceWizard; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; @@ -61,6 +62,7 @@ import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.StyledString; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.pde.internal.core.project.PDEProject; import org.eclipse.pde.internal.core.text.bundle.BundleModel; import org.eclipse.pde.internal.core.text.bundle.ImportPackageHeader; @@ -384,21 +386,26 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { @Override public void onStatusChanged(final ProviderStatus status) { FilteredContributionDialog.this.providerStatus = status; - getShell().getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - updateStatusMessage(); - switch (status) { - case READY: - refreshSearch(); - break; - case CANCELLED: - case INITIALIZING: - break; + try { + getShell().getDisplay().asyncExec(new Runnable() { + + @Override + public void run() { + updateStatusMessage(); + switch (status) { + case READY: + refreshSearch(); + break; + case CANCELLED: + case INITIALIZING: + break; + } } - } - }); + }); + } catch (Exception e2) { + // Dialog may have been closed while + // provider was still indexing + } } }); collector.findContributions(filter, currentResultHandler); @@ -910,23 +917,16 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { // Not a bundle final String bundle = getBundle(file); if (bundle == null) { - NonReferencedResourceDialog dlg = new NonReferencedResourceDialog(getShell(), context.get(IProject.class), bundle, file, installLocation, context) { - @Override - public String getMessage() { - String message = "The resource is not contained in a bundle."; - // message += - // "\nTo access during runtime, you need to copy the resource into this project, or into a referenced project."; - // message += - // "\nYou can also convert the resource's project into a bundle and then import reference the bundle"; - return message; - } - }; - if (dlg.open() == IDialogConstants.OK_ID) { - return dlg.getResult(); + String message = "The selected resource is not contained in a bundle."; + NonReferencedResourceWizard wizard = new NonReferencedResourceWizard(getShell(), context.get(IProject.class), bundle, file, installLocation, context); + wizard.setMessage(message); + WizardDialog wizDlg = new WizardDialog(getShell(), wizard); + wizDlg.setBlockOnOpen(true); + if (wizDlg.open() == IDialogConstants.OK_ID) { + return wizard.getResult(); } else { return null; } - } // Reference by current project @@ -969,9 +969,13 @@ public abstract class FilteredContributionDialog extends TitleAreaDialog { } if (!found) { - NonReferencedResourceDialog dlg = new NonReferencedResourceDialog(getShell(), context.get(IProject.class), bundle, file, installLocation, context); - if (dlg.open() == IDialogConstants.OK_ID) { - return dlg.getResult(); + String message = "The selected resource's bundle is not referenced by this bundle."; + NonReferencedResourceWizard wizard = new NonReferencedResourceWizard(getShell(), context.get(IProject.class), bundle, file, installLocation, context); + wizard.setMessage(message); + WizardDialog wiz = new WizardDialog(getShell(), wizard); + wiz.setBlockOnOpen(true); + if (wiz.open() == IDialogConstants.OK_ID) { + return wizard.getResult(); } else { return null; } diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/DynamicWizard.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/DynamicWizard.java new file mode 100644 index 00000000..1e698bf0 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/DynamicWizard.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation + *******************************************************************************/ + +package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs; + +import java.util.ArrayList; +import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardPage; + +/** + * Adds features for wizards with dynamic pages. The <em>pages</em> member is + * private in the base class... + * + * @author Steven Spungin + * + */ +public class DynamicWizard extends Wizard { + + protected ArrayList<IWizardPage> pages = new ArrayList<IWizardPage>(); + private String message; + + public DynamicWizard() { + setForcePreviousAndNextButtons(true); + } + + @Override + public boolean performFinish() { + return true; + } + + @Override + public boolean canFinish() { + for (IWizardPage page : pages) { + if (page.isPageComplete() == false) { + return false; + } + } + IWizardPage cur = getContainer().getCurrentPage(); + return getNextPage(cur) == null; + } + + @Override + public void addPage(IWizardPage page) { + page.setWizard(this); + pages.add(page); + + // Only add the first page to the base class + if (super.getPageCount() == 0) { + super.addPage(page); + updateMessage(); + } + + } + + /** + * Override the message on the first page if specified + * + * @param page + */ + private void updateMessage() { + if (E.notEmpty(message) && pages.size() > 0) { + // TODO file bug: IWizardPage is missing the setMessage method! + IWizardPage page = pages.get(0); + if (page instanceof WizardPage) { + WizardPage wizPage = (WizardPage) page; + wizPage.setMessage(message); + } + } + } + + @Override + public IWizardPage getPreviousPage(IWizardPage page) { + IWizardPage cur = getContainer().getCurrentPage(); + int index = pages.indexOf(cur); + if (index > 0) { + return pages.get(index - 1); + } else { + return null; + } + } + + @Override + public IWizardPage getNextPage(IWizardPage page) { + int index = pages.indexOf(page); + if (index < pages.size() - 1) { + return pages.get(index + 1); + } else { + return null; + } + } + + public void clearDynamicPages() { + while (pages.size() > 1) { + pages.remove(pages.size() - 1); + } + + } + + /** + * Overrides the message of the first page if not <em>empty</em> + * + * @param message + */ + public void setMessage(String message) { + this.message = message; + updateMessage(); + } + +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedAction.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedAction.java new file mode 100644 index 00000000..e3816c9f --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedAction.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation + *******************************************************************************/ + +package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs; + +/** + * Actions used to resolve non referenced resource issues. + * + * @author Steven Spungin + * + */ +public enum NonReferencedAction { + REQUIRE, IMPORT, COPY, COPY_TO_OTHER, USE_ANYWAY, CONVERT_AND_REQUIRE +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedActionPage.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedActionPage.java new file mode 100644 index 00000000..d62536d1 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedActionPage.java @@ -0,0 +1,492 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation + *******************************************************************************/ + +package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipFile; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.tools.emf.ui.common.IClassContributionProvider.ContributionData; +import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider; +import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.BundleImageCache; +import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.ContributionDataFile; +import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.FilteredContributionDialog; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.BundleConverter; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.pde.internal.core.util.CoreUtility; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +/** + * This page displays information about a non-referenced resource along with + * actions to resolve issues. + * + * @author Steven Spungin + * + */ +public class NonReferencedActionPage extends WizardPage implements IWizardPage { + + private IProject project; + private String bundle; + private IFile file; + private String installLocation; + private IEclipseContext context; + private String className; + private BundleImageCache imageCache; + + protected NonReferencedActionPage(IProject project, String bundle, IFile file, String installLocation, IEclipseContext context) { + super("Nonreferenced Resource Action"); + + this.project = project; + this.bundle = bundle; + this.file = file; + this.installLocation = installLocation; + this.context = context; + + imageCache = context.get(BundleImageCache.class); + + setImageDescriptor(ImageDescriptor.createFromImage(imageCache.create("org.eclipse.e4.tools.emf.ui", "/icons/full/wizban/newefix_wizban.png"))); //$NON-NLS-1$ //$NON-NLS-2$ + + if (bundle == null && installLocation != null) { + this.bundle = FilteredContributionDialog.getBundle(installLocation); + } + if (file instanceof ContributionDataFile) { + ContributionDataFile cdf = (ContributionDataFile) file; + this.className = cdf.getContributionData().className; + } + + setTitle("Nonreferenced Resource Action"); + setMessage("Nonreferenced Resource Action"); + } + + @Override + public void setDescription(String description) { + super.setDescription(description); + super.setMessage(description); + } + + @Override + public void createControl(Composite compParent) { + Composite comp = new Composite(compParent, SWT.NONE); + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + layoutData.horizontalSpan = 2; + comp.setLayoutData(layoutData); + comp.setLayout(new GridLayout(2, false)); + + String message = ""; //$NON-NLS-1$ + Button defaultButton = null; + + if (installLocation != null) { + Label label = new Label(comp, SWT.NONE); + label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label.setText(Messages.NonReferencedResourceDialog_installLocation); + + Text label2 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + label2.setText(installLocation); + } + + if (className != null) { + ContributionData cd = ((ContributionDataFile) file).getContributionData(); + Label label = new Label(comp, SWT.NONE); + label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label.setText(Messages.NonReferencedResourceDialog_2); + + Text label2 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (bundle != null) { + label2.setText(bundle); + } else { + label2.setText(Messages.NonReferencedResourceDialog__ast_notInABundle_ast); + } + + Label label3 = new Label(comp, SWT.NONE); + label3.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label3.setText(Messages.NonReferencedResourceDialog_package); + + Text label4 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + label4.setText(getPackageFromClassName(className)); + + Label label5 = new Label(comp, SWT.NONE); + label5.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label5.setText(Messages.NonReferencedResourceDialog_class); + + Text label6 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + label6.setText(cd.className.substring(cd.className.lastIndexOf('.') + 1)); + + if (bundle != null) { + Label label7 = new Label(comp, SWT.NONE); + label7.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label7.setText(Messages.NonReferencedResourceDialog_url); + + Text label8 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label8.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + label8.setText("bundleclass://" + bundle + "/" + className); //$NON-NLS-1$ //$NON-NLS-2$ + } + } else { + Label label = new Label(comp, SWT.NONE); + label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label.setText(Messages.NonReferencedResourceDialog_bundle); + + Text label2 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + if (bundle != null) { + label2.setText(bundle); + } else { + label2.setText(Messages.NonReferencedResourceDialog_ast_notInABundle_ast); + } + + Label label7 = new Label(comp, SWT.NONE); + label7.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label7.setText(Messages.NonReferencedResourceDialog_directory); + + Text label8 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label8.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + label8.setText(file.getFullPath().removeFirstSegments(1).removeLastSegments(1).toOSString()); + + Label label3 = new Label(comp, SWT.NONE); + label3.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label3.setText(Messages.NonReferencedResourceDialog_resource); + + Text label4 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + label4.setText(file.getFullPath().lastSegment()); + + if (bundle != null) { + Label label5 = new Label(comp, SWT.NONE); + label5.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + label5.setText(Messages.NonReferencedResourceDialog_url); + + Text label6 = new Text(comp, SWT.SINGLE | SWT.LEAD | SWT.READ_ONLY); + label6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + label6.setText("platform:/plugin/" + bundle + "/" + file.getFullPath().removeFirstSegments(1).toOSString()); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + Label lblMessage = new Label(comp, SWT.NONE); + lblMessage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 0)); + lblMessage.setText(message); + + Group group = new Group(comp, SWT.NONE); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 0)); + group.setLayout(new GridLayout(1, false)); + group.setText("Action"); + + if (bundle != null) { + final Button btnRequire = new Button(group, SWT.RADIO); + btnRequire.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + btnRequire.setText(Messages.NonReferencedResourceDialog_requireBundle); + btnRequire.setImage(imageCache.loadFromKey(ResourceProvider.IMG_Obj16_bundle)); + btnRequire.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (btnRequire.getSelection()) { + Runnable okAction = new Runnable() { + + @Override + public void run() { + doRequireBundle(bundle, installLocation); + } + }; + setAction(NonReferencedAction.REQUIRE, okAction); + } + } + }); + defaultButton = btnRequire; + } + + // make sure className is not in the default package (contains '.') + if (className != null && bundle != null && className.contains(".")) { //$NON-NLS-1$ + final Button btnImport = new Button(group, SWT.RADIO); + btnImport.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + btnImport.setText(Messages.NonReferencedResourceDialog_importPackage); + btnImport.setImage(imageCache.create("/icons/full/obj16/package_obj.gif")); //$NON-NLS-1$ + btnImport.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (btnImport.getSelection()) { + Runnable okAction = new Runnable() { + @Override + public void run() { + IFile fileManifest = project.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$ + Manifest manifest; + try { + manifest = new Manifest(fileManifest.getContents()); + String value = manifest.getMainAttributes().getValue("Import-Package"); //$NON-NLS-1$ + + String packageName = getPackageFromClassName(className); + // TODO ensure the packageName is not + // already in the manifest (although it + // should not be if we are here) + if (value == null) { + value = packageName; + } else { + value += "," + packageName; //$NON-NLS-1$ + } + manifest.getMainAttributes().putValue("Import-Package", value); //$NON-NLS-1$ + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + manifest.write(bos); + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + fileManifest.setContents(bis, true, true, null); + context.set("resolvedFile", file); //$NON-NLS-1$ + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + setAction(NonReferencedAction.IMPORT, okAction); + } + } + }); + } + + if (bundle != null) { + final Button btnUseAnyway = new Button(group, SWT.RADIO); + btnUseAnyway.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + btnUseAnyway.setText(Messages.NonReferencedResourceDialog_useAnyway); + btnUseAnyway.setImage(imageCache.create("/icons/full/obj16/use_anyway.gif")); //$NON-NLS-1$ + btnUseAnyway.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (btnUseAnyway.getSelection()) { + setAction(NonReferencedAction.USE_ANYWAY, new Runnable() { + @Override + public void run() { + context.set("resolvedFile", file); //$NON-NLS-1$ + } + }); + } + } + }); + + } else { + if (file instanceof ContributionDataFile) { + final ContributionDataFile cdf = (ContributionDataFile) file; + final Button btnConvertToBundle = new Button(group, SWT.RADIO); + defaultButton = btnConvertToBundle; + btnConvertToBundle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + btnConvertToBundle.setText(Messages.NonReferencedResourceDialog_convertAndRequire); + btnConvertToBundle.setImage(imageCache.create("/icons/full/obj16/bundle.png")); //$NON-NLS-1$ + btnConvertToBundle.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (btnConvertToBundle.getSelection()) { + Runnable okAction = new Runnable() { + + @Override + public void run() { + String bundleId; + try { + ContributionData contributionData = cdf.getContributionData(); + bundleId = BundleConverter.convertProjectToBundle(contributionData.installLocation, project.getWorkspace()); + if (bundleId != null) { + + ContributionData cdConverted = new ContributionData(bundleId, contributionData.className, contributionData.sourceType, contributionData.iconPath); + cdConverted.installLocation = installLocation; + cdConverted.resourceRelativePath = Path.fromOSString(contributionData.iconPath).removeFirstSegments(1).toOSString(); + doRequireBundle(bundleId, installLocation); + context.set("resolvedFile", new ContributionDataFile(cdConverted)); //$NON-NLS-1$ + } + } catch (Exception e1) { + MessageDialog.openError(getShell(), Messages.NonReferencedResourceDialog_error, e1.getMessage()); + } + } + }; + setAction(NonReferencedAction.CONVERT_AND_REQUIRE, okAction); + } + } + }); + } + } + + if (className == null) { + final Button btnCopy = new Button(group, SWT.RADIO); + defaultButton = btnCopy; + btnCopy.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + btnCopy.setText(Messages.NonReferencedResourceDialog_copyToThisProject); + btnCopy.setImage(imageCache.create("/icons/full/obj16/copy_to_project.png")); //$NON-NLS-1$ + btnCopy.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (btnCopy.getSelection()) { + Runnable okAction = new Runnable() { + + @Override + public void run() { + copyResourceToProject(); + } + }; + context.set("projectToCopyTo", project); //$NON-NLS-1$ + setAction(NonReferencedAction.COPY, okAction); + } + } + }); + } + + if (className == null) { + final Button btnCopy2 = new Button(group, SWT.RADIO); + btnCopy2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); + btnCopy2.setText(Messages.NonReferencedResourceDialog_copyToReferenedProject); + btnCopy2.setImage(imageCache.create("/icons/full/obj16/copy_to_project.png")); //$NON-NLS-1$ + btnCopy2.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (btnCopy2.getSelection()) { + + Runnable okAction = new Runnable() { + + @Override + public void run() { + copyResourceToProject(); + } + }; + setAction(NonReferencedAction.COPY_TO_OTHER, okAction); + } + } + }); + } + + if (defaultButton != null) { + defaultButton.setSelection(true); + defaultButton.notifyListeners(SWT.Selection, new Event()); + } + + setControl(comp); + + } + + protected void setAction(NonReferencedAction action, Runnable runnable) { + context.set(NonReferencedAction.class, action); + context.set(Runnable.class, runnable); + if (getContainer().getCurrentPage() != null) { + getContainer().updateButtons(); + } + } + + public void copyResourceToProject() { + IProject project = (IProject) context.get("projectToCopyTo"); //$NON-NLS-1$ + String path = (String) context.get("folderToCopyTo"); //$NON-NLS-1$ + try { + // String filename = ((ContributionDataFile) + // file).getContributionData().className + ".class"; + IPath newPath = Path.fromOSString(path); + if (newPath.isEmpty() == false) { + CoreUtility.createFolder(project.getFolder(newPath)); + } + if (className != null) { + newPath.append(className + ".class"); //$NON-NLS-1$ + } else { + String name = file.getFullPath().lastSegment(); + newPath = newPath.append(name); + } + IFile fileClone = project.getFile(newPath); + fileClone.create(file.getContents(), false, null); + context.set("resolvedFile", fileClone); //$NON-NLS-1$ + } catch (CoreException e1) { + e1.printStackTrace(); + MessageDialog.openError(getShell(), "Error", e1.getMessage()); //$NON-NLS-1$ + } + } + + public void doRequireBundle(String bundle, String installLocation) { + + // Get source bundle version from manifest + String version = null; + InputStream srcStream = null; + try { + Manifest manifestSource; + if (installLocation.endsWith(".jar")) { //$NON-NLS-1$ + ZipFile zip = new ZipFile(installLocation); + srcStream = zip.getInputStream(zip.getEntry("META-INF/MANIFEST.MF")); //$NON-NLS-1$ + manifestSource = new Manifest(srcStream); + zip.close(); + } else { + srcStream = new BufferedInputStream(new FileInputStream(installLocation + "/META-INF/MANIFEST.MF")); //$NON-NLS-1$ + manifestSource = new Manifest(srcStream); + } + version = manifestSource.getMainAttributes().getValue("Bundle-Version"); //$NON-NLS-1$ + if (version != null) { + version = version.replaceFirst("\\.qualifier", ""); //$NON-NLS-1$ //$NON-NLS-2$ + } + } catch (Exception e) { + e.printStackTrace(); + return; + } finally { + try { + srcStream.close(); + } catch (Exception e) { + } + } + + IFile fileManifest = project.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$ + Manifest manifest; + try { + manifest = new Manifest(fileManifest.getContents()); + String value = manifest.getMainAttributes().getValue("Require-Bundle"); //$NON-NLS-1$ + if (value == null) { + manifest.getMainAttributes().putValue("Require-Bundle", bundle); //$NON-NLS-1$ + } else { + value += "," + bundle; //$NON-NLS-1$ + if (version != null) { + value += ";bundle-version=" + version; //$NON-NLS-1$ + } + manifest.getMainAttributes().putValue("Require-Bundle", value); //$NON-NLS-1$ + } + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + manifest.write(bos); + // StringReader reader = new + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + fileManifest.setContents(bis, true, true, null); + context.set("resolvedFile", file); //$NON-NLS-1$ + } catch (IOException e1) { + e1.printStackTrace(); + } catch (CoreException e1) { + e1.printStackTrace(); + } + } + + // @Refactor + static public String getPackageFromClassName(String className) { + int index = className.lastIndexOf('.'); + if (index >= 0) { + return className.substring(0, index); + } else { + return ""; //$NON-NLS-1$ + } + } + +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedResourceWizard.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedResourceWizard.java new file mode 100644 index 00000000..dbb731ca --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/NonReferencedResourceWizard.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 436848 + *******************************************************************************/ + +package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.BundleImageCache; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.widgets.Shell; + +/** + * A Wizard for resolving unreferenced resources + * + * @author Steven Spungin + * + */ +public class NonReferencedResourceWizard extends DynamicWizard { + + private NonReferencedActionPage nonReferencedActionPage; + protected IProject project; + IEclipseContext wizContext; + + BundleImageCache imageCache; + + public NonReferencedResourceWizard(Shell parentShell, IProject project, String bundle, IFile file, String installLocation, IEclipseContext context) { + this.project = project; + + wizContext = context.createChild(); + wizContext.set(IProject.class, project); + wizContext.set("srcPath", file.getFullPath().toOSString()); //$NON-NLS-1$ + wizContext.set(Runnable.class, null); + wizContext.set("resolvedFile", null); //$NON-NLS-1$ + + imageCache = new BundleImageCache(parentShell.getDisplay(), getClass().getClassLoader(), context); + parentShell.addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + imageCache.dispose(); + } + }); + wizContext.set(BundleImageCache.class, imageCache); + + nonReferencedActionPage = new NonReferencedActionPage(project, bundle, file, installLocation, wizContext); + } + + @Override + public boolean performFinish() { + Runnable action = wizContext.get(Runnable.class); + if (action != null) { + action.run(); + } + return true; + } + + public IFile getResult() { + return (IFile) wizContext.get("resolvedFile"); //$NON-NLS-1$ + } + + @Override + public IWizardPage getNextPage(IWizardPage page) { + if (page instanceof NonReferencedActionPage) { + clearDynamicPages(); + NonReferencedAction action = wizContext.get(NonReferencedAction.class); + if (action == null) { + return null; + } + switch (action) { + case COPY: { + PickProjectFolderPage pickProjectFolderPage = new PickProjectFolderPage(wizContext); + addPage(pickProjectFolderPage); + return pickProjectFolderPage; + } + case COPY_TO_OTHER: + PickProjectPage pickProjectPage = new PickProjectPage(wizContext); + addPage(pickProjectPage); + PickProjectFolderPage pickProjectFolderPage = new PickProjectFolderPage(wizContext); + addPage(pickProjectFolderPage); + return pickProjectPage; + case USE_ANYWAY: + return null; + case IMPORT: + // TODO Page to set version + return null; + case REQUIRE: + // TODO Page to set version + return null; + case CONVERT_AND_REQUIRE: + // TODO Page for new bundle's information + return null; + default: + return null; + } + } else { + return super.getNextPage(page); + } + } + + @Override + public void addPages() { + addPage(nonReferencedActionPage); + } +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/PickProjectFolderPage.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/PickProjectFolderPage.java new file mode 100644 index 00000000..0c5f8c24 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/PickProjectFolderPage.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation + *******************************************************************************/ + +package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.BundleImageCache; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.ProjectFolderPickerDialog.ProjectContentProvider; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs.ProjectFolderPickerDialog.ProjectLabelProvider; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +/** + * Wizard page to select a project folder + * + * @author Steven Spungin + * + */ +public class PickProjectFolderPage extends WizardPage { + + private TreeViewer viewer; + private String value; + private IEclipseContext context; + private IPath path; + + private Label label2; + private Label label3; + private Label lblResourcePath; + + protected PickProjectFolderPage(IEclipseContext context) { + super("Select Project Folder", "Select Project Folder", null); + this.context = context; + + setMessage(Messages.NonReferencedResourceDialog_selectProjectToReceiveCopy); + Image image = context.get(BundleImageCache.class).create("/icons/full/wizban/plugin_wiz.gif"); //$NON-NLS-1$ + setImageDescriptor(ImageDescriptor.createFromImage(image)); + setPageComplete(false); + } + + @Override + public void createControl(Composite parent) { + // TODO Auto-generated method stub + Composite ret = new Composite(parent, SWT.NONE); + // ret.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + ret.setLayout(new GridLayout(1, false)); + + viewer = new TreeViewer(ret); + viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); + viewer.setContentProvider(new ProjectContentProvider()); + viewer.setLabelProvider(new ProjectLabelProvider()); + viewer.expandToLevel(2); + + viewer.addDoubleClickListener(new IDoubleClickListener() { + + @Override + public void doubleClick(DoubleClickEvent event) { + onChanged(); + } + }); + + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + onChanged(); + } + }); + + Composite compPath = new Composite(ret, SWT.NONE); + compPath.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + compPath.setLayout(new GridLayout(2, false)); + + Label label = new Label(compPath, SWT.NONE); + label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + label.setText(Messages.ProjectFolderPickerDialog_sourceResourceName); + + label2 = new Label(compPath, SWT.NONE); + label2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + + label3 = new Label(compPath, SWT.NONE); + label3.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + + lblResourcePath = new Label(compPath, SWT.NONE); + lblResourcePath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + compPath.setVisible(false); + + String message = Messages.ProjectFolderPickerDialog_6; + + getShell().setText(message); + setTitle(message); + setMessage(message); + setControl(ret); + } + + @Override + public void setVisible(boolean visible) { + if (visible) { + IProject project = (IProject) context.get("projectToCopyTo"); //$NON-NLS-1$ + viewer.setInput(project); + + Object object = context.get("folderToCopyTo.obj"); //$NON-NLS-1$ + if (object != null) { + viewer.setSelection(new StructuredSelection(object)); + } else { + viewer.setSelection(new StructuredSelection()); + } + setPageComplete(viewer.getSelection().isEmpty() == false); + + path = new Path((String) context.get("srcPath")); //$NON-NLS-1$ + label2.setText(path.lastSegment()); + label3.setText(Messages.ProjectFolderPickerDialog_sourceResourceDirectory); + lblResourcePath.setText(path.removeLastSegments(1).toOSString()); + } + super.setVisible(visible); + } + + protected void onChanged() { + Object selected = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); + if (selected == null || selected instanceof String) { + value = ""; //$NON-NLS-1$ + } else { + IResource resource = (IResource) selected; + value = resource.getFullPath().removeFirstSegments(1).toOSString(); + } + context.set("folderToCopyTo", value); //$NON-NLS-1$ + context.set("folderToCopyTo.obj", selected); //$NON-NLS-1$ + setPageComplete(selected != null); + } +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/PickProjectPage.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/PickProjectPage.java new file mode 100644 index 00000000..14a837d0 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/resourcelocator/dialogs/PickProjectPage.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2014 TwelveTone LLC 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: + * Steven Spungin <steven@spungin.tv> - initial API and implementation + *******************************************************************************/ + +package org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.dialogs; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.BundleImageCache; +import org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.Messages; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + +/** + * Wizard page to select a referenced project + * + * @author Steven Spungin + * + */ +public class PickProjectPage extends WizardPage implements IWizardPage { + + private TableViewer viewer; + private BundleImageCache imageCache; + private Image imgProject; + private IProject[] projects; + private IEclipseContext context; + + protected PickProjectPage(IEclipseContext context) { + super("Select Referenced Project"); + this.context = context; + try { + this.projects = context.get(IProject.class).getReferencedProjects(); + } catch (CoreException e) { + setErrorMessage(e.getMessage()); + e.printStackTrace(); + } + setPageComplete(false); + } + + @Override + public void createControl(Composite parent) { + + imageCache = new BundleImageCache(parent.getDisplay(), getClass().getClassLoader()); + getShell().addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + imageCache.dispose(); + imgProject = null; + } + }); + imgProject = imageCache.create("/icons/full/obj16/projects.png"); //$NON-NLS-1$ + + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + comp.setLayout(new GridLayout(1, false)); + + viewer = new TableViewer(comp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); + viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); + viewer.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + IProject project = (IProject) element; + return project.getName(); + } + + @Override + public Image getImage(Object element) { + return imgProject; + } + }); + viewer.setContentProvider(ArrayContentProvider.getInstance()); + + viewer.setInput(projects); + + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + Object firstElement = ((StructuredSelection) event.getSelection()).getFirstElement(); + context.set("projectToCopyTo", firstElement); //$NON-NLS-1$ + setPageComplete(firstElement != null); + getContainer().updateButtons(); + } + }); + + String message = Messages.ReferencedProjectPickerDialog_selectReferencedProject; + setMessage(message); + getShell().setText(message); + setTitle(message); + + Image image = context.get(BundleImageCache.class).create("/icons/full/obj16/projects.png"); //$NON-NLS-1$ + setImageDescriptor(ImageDescriptor.createFromImage(image)); + + setControl(comp); + } + + @Override + public void setVisible(boolean visible) { + Object object = context.get("projectToCopyTo"); //$NON-NLS-1$ + if (visible) { + if (object != null) { + viewer.setSelection(new StructuredSelection(object)); + } else { + viewer.setSelection(new StructuredSelection()); + } + } + setPageComplete(viewer.getSelection().isEmpty() == false); + super.setVisible(visible); + } + +} |