0001: /*******************************************************************************
0002: * Copyright (c) 2000, 2007 IBM Corporation and others.
0003: * All rights reserved. This program and the accompanying materials
0004: * are made available under the terms of the Eclipse Public License v1.0
0005: * which accompanies this distribution, and is available at
0006: * http://www.eclipse.org/legal/epl-v10.html
0007: *
0008: * Contributors:
0009: * IBM Corporation - initial API and implementation
0010: *******************************************************************************/package org.eclipse.jdt.internal.ui.jarpackager;
0011:
0012: import java.lang.reflect.InvocationTargetException;
0013: import java.util.ArrayList;
0014: import java.util.Arrays;
0015: import java.util.HashSet;
0016: import java.util.Iterator;
0017: import java.util.List;
0018: import java.util.Set;
0019: import java.util.jar.Attributes;
0020: import java.util.jar.Manifest;
0021:
0022: import org.eclipse.core.runtime.CoreException;
0023: import org.eclipse.core.runtime.IPath;
0024: import org.eclipse.core.runtime.IStatus;
0025: import org.eclipse.core.runtime.Path;
0026:
0027: import org.eclipse.core.resources.IFile;
0028: import org.eclipse.core.resources.IResource;
0029: import org.eclipse.core.resources.IWorkspace;
0030:
0031: import org.eclipse.swt.SWT;
0032: import org.eclipse.swt.events.KeyAdapter;
0033: import org.eclipse.swt.events.KeyEvent;
0034: import org.eclipse.swt.events.SelectionAdapter;
0035: import org.eclipse.swt.events.SelectionEvent;
0036: import org.eclipse.swt.layout.GridData;
0037: import org.eclipse.swt.layout.GridLayout;
0038: import org.eclipse.swt.widgets.Button;
0039: import org.eclipse.swt.widgets.Composite;
0040: import org.eclipse.swt.widgets.Control;
0041: import org.eclipse.swt.widgets.Event;
0042: import org.eclipse.swt.widgets.Label;
0043: import org.eclipse.swt.widgets.Listener;
0044: import org.eclipse.swt.widgets.Text;
0045:
0046: import org.eclipse.jface.dialogs.Dialog;
0047: import org.eclipse.jface.dialogs.IDialogSettings;
0048: import org.eclipse.jface.dialogs.IMessageProvider;
0049: import org.eclipse.jface.resource.JFaceResources;
0050: import org.eclipse.jface.viewers.DecoratingLabelProvider;
0051: import org.eclipse.jface.window.Window;
0052: import org.eclipse.jface.wizard.IWizardPage;
0053: import org.eclipse.jface.wizard.WizardPage;
0054:
0055: import org.eclipse.ui.PlatformUI;
0056: import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
0057: import org.eclipse.ui.dialogs.ISelectionStatusValidator;
0058: import org.eclipse.ui.dialogs.SaveAsDialog;
0059: import org.eclipse.ui.dialogs.SelectionDialog;
0060:
0061: import org.eclipse.jdt.core.ICompilationUnit;
0062: import org.eclipse.jdt.core.IPackageFragment;
0063: import org.eclipse.jdt.core.IPackageFragmentRoot;
0064: import org.eclipse.jdt.core.IType;
0065: import org.eclipse.jdt.core.JavaCore;
0066: import org.eclipse.jdt.core.JavaModelException;
0067: import org.eclipse.jdt.core.search.IJavaSearchScope;
0068:
0069: import org.eclipse.jdt.internal.corext.util.Messages;
0070:
0071: import org.eclipse.jdt.ui.JavaElementComparator;
0072: import org.eclipse.jdt.ui.JavaElementLabelProvider;
0073: import org.eclipse.jdt.ui.JavaUI;
0074: import org.eclipse.jdt.ui.ProblemsLabelDecorator;
0075: import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
0076: import org.eclipse.jdt.ui.jarpackager.JarPackageData;
0077:
0078: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
0079: import org.eclipse.jdt.internal.ui.JavaPlugin;
0080: import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
0081: import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
0082: import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
0083: import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
0084: import org.eclipse.jdt.internal.ui.util.MainMethodSearchEngine;
0085: import org.eclipse.jdt.internal.ui.util.SWTUtil;
0086: import org.eclipse.jdt.internal.ui.viewsupport.LibraryFilter;
0087:
0088: /**
0089: * Page 3 of the JAR Package wizard
0090: */
0091: class JarManifestWizardPage extends WizardPage implements
0092: IJarPackageWizardPage {
0093:
0094: // Untyped listener
0095: private class UntypedListener implements Listener {
0096: /*
0097: * Implements method from Listener
0098: */
0099: public void handleEvent(Event e) {
0100: if (getControl() == null)
0101: return;
0102: update();
0103: }
0104: }
0105:
0106: private UntypedListener fUntypedListener = new UntypedListener();
0107:
0108: // Model
0109: private JarPackageData fJarPackage;
0110:
0111: // Cache for main types
0112: private IType[] fMainTypes;
0113:
0114: // Widgets
0115: private Composite fManifestGroup;
0116: private Button fGenerateManifestRadioButton;
0117: private Button fSaveManifestCheckbox;
0118: private Button fReuseManifestCheckbox;
0119: private Text fNewManifestFileText;
0120: private Label fNewManifestFileLabel;
0121: private Button fNewManifestFileBrowseButton;
0122: private Button fUseManifestRadioButton;
0123: private Text fManifestFileText;
0124: private Label fManifestFileLabel;
0125: private Button fManifestFileBrowseButton;
0126:
0127: private Label fSealingHeaderLabel;
0128: private Button fSealJarRadioButton;
0129: private Label fSealJarLabel;
0130: private Button fSealedPackagesDetailsButton;
0131: private Button fSealPackagesRadioButton;
0132: private Label fSealPackagesLabel;
0133: private Button fUnSealedPackagesDetailsButton;
0134:
0135: private Label fMainClassHeaderLabel;
0136: private Label fMainClassLabel;
0137: private Text fMainClassText;
0138: private Button fMainClassBrowseButton;
0139:
0140: // Dialog store id constants
0141: private final static String PAGE_NAME = "JarManifestWizardPage"; //$NON-NLS-1$
0142:
0143: // Manifest creation
0144: private final static String STORE_GENERATE_MANIFEST = PAGE_NAME
0145: + ".GENERATE_MANIFEST"; //$NON-NLS-1$
0146: private final static String STORE_SAVE_MANIFEST = PAGE_NAME
0147: + ".SAVE_MANIFEST"; //$NON-NLS-1$
0148: private final static String STORE_REUSE_MANIFEST = PAGE_NAME
0149: + ".REUSE_MANIFEST"; //$NON-NLS-1$
0150: private final static String STORE_MANIFEST_LOCATION = PAGE_NAME
0151: + ".MANIFEST_LOCATION"; //$NON-NLS-1$
0152:
0153: // Sealing
0154: private final static String STORE_SEAL_JAR = PAGE_NAME
0155: + ".SEAL_JAR"; //$NON-NLS-1$
0156:
0157: /**
0158: * Create an instance of this class
0159: */
0160: public JarManifestWizardPage(JarPackageData jarPackage) {
0161: super (PAGE_NAME);
0162: setTitle(JarPackagerMessages.JarManifestWizardPage_title);
0163: setDescription(JarPackagerMessages.JarManifestWizardPage_description);
0164: fJarPackage = jarPackage;
0165: }
0166:
0167: // ----------- Widget creation -----------
0168:
0169: /*
0170: * Method declared on IDialogPage.
0171: */
0172: public void createControl(Composite parent) {
0173:
0174: initializeDialogUnits(parent);
0175:
0176: Composite composite = new Composite(parent, SWT.NULL);
0177: composite.setLayout(new GridLayout());
0178: composite.setLayoutData(new GridData(
0179: GridData.VERTICAL_ALIGN_FILL
0180: | GridData.HORIZONTAL_ALIGN_FILL));
0181:
0182: createLabel(
0183: composite,
0184: JarPackagerMessages.JarManifestWizardPage_manifestSource_label,
0185: false);
0186: createManifestGroup(composite);
0187:
0188: createSpacer(composite);
0189:
0190: fSealingHeaderLabel = createLabel(
0191: composite,
0192: JarPackagerMessages.JarManifestWizardPage_sealingHeader_label,
0193: false);
0194: createSealingGroup(composite);
0195:
0196: createSpacer(composite);
0197:
0198: fMainClassHeaderLabel = createLabel(
0199: composite,
0200: JarPackagerMessages.JarManifestWizardPage_mainClassHeader_label,
0201: false);
0202: createMainClassGroup(composite);
0203:
0204: setEqualButtonSizes();
0205:
0206: restoreWidgetValues();
0207:
0208: setControl(composite);
0209: update();
0210:
0211: Dialog.applyDialogFont(composite);
0212: PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
0213: IJavaHelpContextIds.JARMANIFEST_WIZARD_PAGE);
0214:
0215: }
0216:
0217: /**
0218: * Create the export options specification widgets.
0219: *
0220: * @param parent org.eclipse.swt.widgets.Composite
0221: */
0222: protected void createManifestGroup(Composite parent) {
0223: fManifestGroup = new Composite(parent, SWT.NONE);
0224: GridLayout layout = new GridLayout();
0225: fManifestGroup.setLayout(layout);
0226: fManifestGroup.setLayoutData(new GridData(
0227: GridData.HORIZONTAL_ALIGN_FILL
0228: | GridData.VERTICAL_ALIGN_FILL
0229: | GridData.GRAB_HORIZONTAL));
0230:
0231: fGenerateManifestRadioButton = new Button(fManifestGroup,
0232: SWT.RADIO | SWT.LEFT);
0233: fGenerateManifestRadioButton
0234: .setText(JarPackagerMessages.JarManifestWizardPage_genetateManifest_text);
0235: fGenerateManifestRadioButton.addListener(SWT.Selection,
0236: fUntypedListener);
0237:
0238: Composite saveOptions = new Composite(fManifestGroup, SWT.NONE);
0239: GridLayout saveOptionsLayout = new GridLayout();
0240: saveOptionsLayout.marginWidth = 0;
0241: saveOptions.setLayout(saveOptionsLayout);
0242:
0243: GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
0244: | GridData.VERTICAL_ALIGN_FILL
0245: | GridData.GRAB_HORIZONTAL);
0246: data.horizontalIndent = 20;
0247: saveOptions.setLayoutData(data);
0248:
0249: fSaveManifestCheckbox = new Button(saveOptions, SWT.CHECK
0250: | SWT.LEFT);
0251: fSaveManifestCheckbox
0252: .setText(JarPackagerMessages.JarManifestWizardPage_saveManifest_text);
0253: fSaveManifestCheckbox
0254: .addListener(SWT.MouseUp, fUntypedListener);
0255:
0256: fReuseManifestCheckbox = new Button(saveOptions, SWT.CHECK
0257: | SWT.LEFT);
0258: fReuseManifestCheckbox
0259: .setText(JarPackagerMessages.JarManifestWizardPage_reuseManifest_text);
0260: fReuseManifestCheckbox.addListener(SWT.MouseUp,
0261: fUntypedListener);
0262:
0263: createNewManifestFileGroup(saveOptions);
0264:
0265: fUseManifestRadioButton = new Button(fManifestGroup, SWT.RADIO
0266: | SWT.LEFT);
0267: fUseManifestRadioButton
0268: .setText(JarPackagerMessages.JarManifestWizardPage_useManifest_text);
0269:
0270: fUseManifestRadioButton.setLayoutData(new GridData(
0271: GridData.FILL_HORIZONTAL));
0272: Composite existingManifestGroup = new Composite(fManifestGroup,
0273: SWT.NONE);
0274: GridLayout existingManifestLayout = new GridLayout();
0275: existingManifestLayout.marginWidth = 0;
0276: existingManifestGroup.setLayout(existingManifestLayout);
0277: data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
0278: | GridData.VERTICAL_ALIGN_FILL
0279: | GridData.GRAB_HORIZONTAL);
0280: data.horizontalIndent = 20;
0281: existingManifestGroup.setLayoutData(data);
0282: createManifestFileGroup(existingManifestGroup);
0283: }
0284:
0285: protected void createNewManifestFileGroup(Composite parent) {
0286: // destination specification group
0287: Composite manifestFileGroup = new Composite(parent, SWT.NONE);
0288: GridLayout layout = new GridLayout();
0289: layout.marginWidth = 0;
0290: layout.numColumns = 3;
0291: manifestFileGroup.setLayout(layout);
0292: manifestFileGroup.setLayoutData(new GridData(
0293: GridData.HORIZONTAL_ALIGN_FILL
0294: | GridData.VERTICAL_ALIGN_FILL
0295: | GridData.GRAB_HORIZONTAL));
0296:
0297: fNewManifestFileLabel = new Label(manifestFileGroup, SWT.NONE);
0298: fNewManifestFileLabel
0299: .setText(JarPackagerMessages.JarManifestWizardPage_newManifestFile_text);
0300:
0301: // entry field
0302: fNewManifestFileText = new Text(manifestFileGroup, SWT.SINGLE
0303: | SWT.BORDER);
0304: fNewManifestFileText.addListener(SWT.Modify, fUntypedListener);
0305:
0306: GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
0307: | GridData.GRAB_HORIZONTAL);
0308: data.widthHint = convertWidthInCharsToPixels(40);
0309: fNewManifestFileText.setLayoutData(data);
0310:
0311: // browse button
0312: fNewManifestFileBrowseButton = new Button(manifestFileGroup,
0313: SWT.PUSH);
0314: fNewManifestFileBrowseButton
0315: .setText(JarPackagerMessages.JarManifestWizardPage_newManifestFileBrowseButton_text);
0316: fNewManifestFileBrowseButton.setLayoutData(new GridData(
0317: GridData.HORIZONTAL_ALIGN_FILL));
0318: fNewManifestFileBrowseButton
0319: .addSelectionListener(new SelectionAdapter() {
0320: public void widgetSelected(SelectionEvent e) {
0321: handleNewManifestFileBrowseButtonPressed();
0322: }
0323: });
0324: }
0325:
0326: protected void createManifestFileGroup(Composite parent) {
0327: // destination specification group
0328: Composite manifestFileGroup = new Composite(parent, SWT.NONE);
0329: GridLayout layout = new GridLayout();
0330: layout.numColumns = 3;
0331: layout.marginWidth = 0;
0332:
0333: manifestFileGroup.setLayout(layout);
0334: manifestFileGroup.setLayoutData(new GridData(
0335: GridData.HORIZONTAL_ALIGN_FILL
0336: | GridData.VERTICAL_ALIGN_FILL
0337: | GridData.GRAB_HORIZONTAL));
0338:
0339: fManifestFileLabel = new Label(manifestFileGroup, SWT.NONE);
0340: fManifestFileLabel
0341: .setText(JarPackagerMessages.JarManifestWizardPage_manifestFile_text);
0342:
0343: // entry field
0344: fManifestFileText = new Text(manifestFileGroup, SWT.SINGLE
0345: | SWT.BORDER);
0346: fManifestFileText.addListener(SWT.Modify, fUntypedListener);
0347: GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
0348: | GridData.GRAB_HORIZONTAL);
0349: data.widthHint = convertWidthInCharsToPixels(40);
0350: fManifestFileText.setLayoutData(data);
0351:
0352: // browse button
0353: fManifestFileBrowseButton = new Button(manifestFileGroup,
0354: SWT.PUSH);
0355: fManifestFileBrowseButton
0356: .setText(JarPackagerMessages.JarManifestWizardPage_manifestFileBrowse_text);
0357: fManifestFileBrowseButton.setLayoutData(new GridData(
0358: GridData.HORIZONTAL_ALIGN_FILL));
0359: fManifestFileBrowseButton
0360: .addSelectionListener(new SelectionAdapter() {
0361: public void widgetSelected(SelectionEvent e) {
0362: handleManifestFileBrowseButtonPressed();
0363: }
0364: });
0365: }
0366:
0367: /**
0368: * Creates the JAR sealing specification controls.
0369: *
0370: * @param parent the parent control
0371: */
0372: protected void createSealingGroup(Composite parent) {
0373: // destination specification group
0374: Composite sealingGroup = new Composite(parent, SWT.NONE);
0375: GridLayout layout = new GridLayout();
0376: layout.numColumns = 3;
0377: layout.horizontalSpacing += 3;
0378: sealingGroup.setLayout(layout);
0379: sealingGroup.setLayoutData(new GridData(
0380: GridData.HORIZONTAL_ALIGN_FILL
0381: | GridData.VERTICAL_ALIGN_FILL));
0382: createSealJarGroup(sealingGroup);
0383: createSealPackagesGroup(sealingGroup);
0384:
0385: }
0386:
0387: /**
0388: * Creates the JAR sealing specification controls to seal the whole JAR.
0389: *
0390: * @param sealGroup the parent control
0391: */
0392: protected void createSealJarGroup(Composite sealGroup) {
0393: fSealJarRadioButton = new Button(sealGroup, SWT.RADIO);
0394: fSealJarRadioButton
0395: .setText(JarPackagerMessages.JarManifestWizardPage_sealJar_text);
0396: fSealJarRadioButton
0397: .addListener(SWT.Selection, fUntypedListener);
0398:
0399: fSealJarLabel = new Label(sealGroup, SWT.RIGHT);
0400: fSealJarLabel.setLayoutData(new GridData(
0401: GridData.HORIZONTAL_ALIGN_FILL
0402: | GridData.GRAB_HORIZONTAL));
0403: fSealJarLabel.setText(""); //$NON-NLS-1$
0404:
0405: fUnSealedPackagesDetailsButton = new Button(sealGroup, SWT.PUSH);
0406: fUnSealedPackagesDetailsButton.setLayoutData(new GridData(
0407: GridData.HORIZONTAL_ALIGN_FILL));
0408: fUnSealedPackagesDetailsButton
0409: .setText(JarPackagerMessages.JarManifestWizardPage_unsealPackagesButton_text);
0410: fUnSealedPackagesDetailsButton
0411: .addSelectionListener(new SelectionAdapter() {
0412: public void widgetSelected(SelectionEvent e) {
0413: handleUnSealPackagesDetailsButtonPressed();
0414: }
0415: });
0416:
0417: }
0418:
0419: /**
0420: * Creates the JAR sealing specification controls to seal packages.
0421: *
0422: * @param sealGroup the parent control
0423: */
0424: protected void createSealPackagesGroup(Composite sealGroup) {
0425: fSealPackagesRadioButton = new Button(sealGroup, SWT.RADIO);
0426: fSealPackagesRadioButton
0427: .setText(JarPackagerMessages.JarManifestWizardPage_sealPackagesButton_text);
0428:
0429: fSealPackagesLabel = new Label(sealGroup, SWT.RIGHT);
0430: fSealPackagesLabel.setLayoutData(new GridData(
0431: GridData.HORIZONTAL_ALIGN_FILL
0432: | GridData.GRAB_HORIZONTAL));
0433: fSealPackagesLabel.setText(""); //$NON-NLS-1$
0434:
0435: fSealedPackagesDetailsButton = new Button(sealGroup, SWT.PUSH);
0436: fSealedPackagesDetailsButton.setLayoutData(new GridData(
0437: GridData.HORIZONTAL_ALIGN_FILL));
0438: fSealedPackagesDetailsButton
0439: .setText(JarPackagerMessages.JarManifestWizardPage_sealedPackagesDetailsButton_text);
0440: fSealedPackagesDetailsButton
0441: .addSelectionListener(new SelectionAdapter() {
0442: public void widgetSelected(SelectionEvent e) {
0443: handleSealPackagesDetailsButtonPressed();
0444: }
0445: });
0446: }
0447:
0448: protected void createMainClassGroup(Composite parent) {
0449: // main type group
0450: Composite mainClassGroup = new Composite(parent, SWT.NONE);
0451: GridLayout layout = new GridLayout();
0452: layout.numColumns = 3;
0453: mainClassGroup.setLayout(layout);
0454: mainClassGroup.setLayoutData(new GridData(
0455: GridData.HORIZONTAL_ALIGN_FILL
0456: | GridData.VERTICAL_ALIGN_FILL));
0457:
0458: fMainClassLabel = new Label(mainClassGroup, SWT.NONE);
0459: fMainClassLabel
0460: .setText(JarPackagerMessages.JarManifestWizardPage_mainClass_label);
0461:
0462: // entry field
0463: fMainClassText = new Text(mainClassGroup, SWT.SINGLE
0464: | SWT.BORDER);
0465: fMainClassText.addListener(SWT.Modify, fUntypedListener);
0466: GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
0467: | GridData.GRAB_HORIZONTAL);
0468: data.widthHint = convertWidthInCharsToPixels(40);
0469: fMainClassText.setLayoutData(data);
0470: fMainClassText.addKeyListener(new KeyAdapter() {
0471: /*
0472: * @see KeyListener#keyReleased(KeyEvent)
0473: */
0474: public void keyReleased(KeyEvent e) {
0475: fJarPackage
0476: .setManifestMainClass(findMainMethodByName(fMainClassText
0477: .getText()));
0478: update();
0479: }
0480: });
0481:
0482: // browse button
0483: fMainClassBrowseButton = new Button(mainClassGroup, SWT.PUSH);
0484: fMainClassBrowseButton
0485: .setText(JarPackagerMessages.JarManifestWizardPage_mainClassBrowseButton_text);
0486: fMainClassBrowseButton.setLayoutData(new GridData(
0487: GridData.HORIZONTAL_ALIGN_FILL));
0488: fMainClassBrowseButton
0489: .addSelectionListener(new SelectionAdapter() {
0490: public void widgetSelected(SelectionEvent e) {
0491: handleMainClassBrowseButtonPressed();
0492: }
0493: });
0494: }
0495:
0496: // ----------- Event handlers -----------
0497:
0498: private void update() {
0499: updateModel();
0500: updateEnableState();
0501: updatePageCompletion();
0502: }
0503:
0504: /**
0505: * Open an appropriate dialog so that the user can specify a manifest
0506: * to save
0507: */
0508: protected void handleNewManifestFileBrowseButtonPressed() {
0509: // Use Save As dialog to select a new file inside the workspace
0510: SaveAsDialog dialog = new SaveAsDialog(getContainer()
0511: .getShell());
0512: dialog.create();
0513: dialog
0514: .getShell()
0515: .setText(
0516: JarPackagerMessages.JarManifestWizardPage_saveAsDialog_title);
0517: dialog
0518: .setMessage(JarPackagerMessages.JarManifestWizardPage_saveAsDialog_message);
0519: dialog.setOriginalFile(createFileHandle(fJarPackage
0520: .getManifestLocation()));
0521: if (dialog.open() == Window.OK) {
0522: fJarPackage.setManifestLocation(dialog.getResult());
0523: fNewManifestFileText.setText(dialog.getResult().toString());
0524: }
0525: }
0526:
0527: protected void handleManifestFileBrowseButtonPressed() {
0528: ElementTreeSelectionDialog dialog = createWorkspaceFileSelectionDialog(
0529: JarPackagerMessages.JarManifestWizardPage_manifestSelectionDialog_title,
0530: JarPackagerMessages.JarManifestWizardPage_manifestSelectionDialog_message);
0531: if (fJarPackage.isManifestAccessible())
0532: dialog.setInitialSelections(new IResource[] { fJarPackage
0533: .getManifestFile() });
0534: if (dialog.open() == Window.OK) {
0535: Object[] resources = dialog.getResult();
0536: if (resources.length != 1)
0537: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_onlyOneManifestMustBeSelected);
0538: else {
0539: setErrorMessage(""); //$NON-NLS-1$
0540: fJarPackage
0541: .setManifestLocation(((IResource) resources[0])
0542: .getFullPath());
0543: fManifestFileText.setText(fJarPackage
0544: .getManifestLocation().toString());
0545: }
0546: }
0547: }
0548:
0549: private IType findMainMethodByName(String name) {
0550: if (fMainTypes == null) {
0551: List resources = JarPackagerUtil.asResources(fJarPackage
0552: .getElements());
0553: if (resources == null) {
0554: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_noResourceSelected);
0555: return null;
0556: }
0557: IJavaSearchScope searchScope = JavaSearchScopeFactory
0558: .getInstance().createJavaSearchScope(
0559: (IResource[]) resources
0560: .toArray(new IResource[resources
0561: .size()]), true);
0562: MainMethodSearchEngine engine = new MainMethodSearchEngine();
0563: try {
0564: fMainTypes = engine.searchMainMethods(getContainer(),
0565: searchScope, 0);
0566: } catch (InvocationTargetException ex) {
0567: // null
0568: } catch (InterruptedException e) {
0569: // null
0570: }
0571: }
0572: for (int i = 0; i < fMainTypes.length; i++) {
0573: if (fMainTypes[i].getFullyQualifiedName().equals(name))
0574: return fMainTypes[i];
0575: }
0576: return null;
0577: }
0578:
0579: protected void handleMainClassBrowseButtonPressed() {
0580: List resources = JarPackagerUtil.asResources(fJarPackage
0581: .getElements());
0582: if (resources == null) {
0583: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_noResourceSelected);
0584: return;
0585: }
0586: IJavaSearchScope searchScope = JavaSearchScopeFactory
0587: .getInstance()
0588: .createJavaSearchScope(
0589: (IResource[]) resources
0590: .toArray(new IResource[resources.size()]),
0591: true);
0592: SelectionDialog dialog = JavaUI.createMainTypeDialog(
0593: getContainer().getShell(), getContainer(), searchScope,
0594: 0, false, ""); //$NON-NLS-1$
0595: dialog
0596: .setTitle(JarPackagerMessages.JarManifestWizardPage_mainTypeSelectionDialog_title);
0597: dialog
0598: .setMessage(JarPackagerMessages.JarManifestWizardPage_mainTypeSelectionDialog_message);
0599: if (fJarPackage.getManifestMainClass() != null)
0600: dialog.setInitialSelections(new Object[] { fJarPackage
0601: .getManifestMainClass() });
0602:
0603: if (dialog.open() == Window.OK) {
0604: fJarPackage
0605: .setManifestMainClass((IType) dialog.getResult()[0]);
0606: fMainClassText.setText(JarPackagerUtil
0607: .getMainClassName(fJarPackage));
0608: } else if (!fJarPackage.isMainClassValid(getContainer())) {
0609: // user did not cancel: no types were found
0610: fJarPackage.setManifestMainClass(null);
0611: fMainClassText.setText(JarPackagerUtil
0612: .getMainClassName(fJarPackage));
0613: }
0614: }
0615:
0616: protected void handleSealPackagesDetailsButtonPressed() {
0617: SelectionDialog dialog = createPackageDialog(getPackagesForSelectedResources(fJarPackage));
0618: dialog
0619: .setTitle(JarPackagerMessages.JarManifestWizardPage_sealedPackagesSelectionDialog_title);
0620: dialog
0621: .setMessage(JarPackagerMessages.JarManifestWizardPage_sealedPackagesSelectionDialog_message);
0622: dialog.setInitialSelections(fJarPackage.getPackagesToSeal());
0623: if (dialog.open() == Window.OK)
0624: fJarPackage
0625: .setPackagesToSeal(getPackagesFromDialog(dialog));
0626: updateSealingInfo();
0627: }
0628:
0629: protected void handleUnSealPackagesDetailsButtonPressed() {
0630: SelectionDialog dialog = createPackageDialog(getPackagesForSelectedResources(fJarPackage));
0631: dialog
0632: .setTitle(JarPackagerMessages.JarManifestWizardPage_unsealedPackagesSelectionDialog_title);
0633: dialog
0634: .setMessage(JarPackagerMessages.JarManifestWizardPage_unsealedPackagesSelectionDialog_message);
0635: dialog.setInitialSelections(fJarPackage.getPackagesToUnseal());
0636: if (dialog.open() == Window.OK)
0637: fJarPackage
0638: .setPackagesToUnseal(getPackagesFromDialog(dialog));
0639: updateSealingInfo();
0640: }
0641:
0642: /**
0643: * Updates the enable state of this page's controls. Subclasses may extend.
0644: */
0645: protected void updateEnableState() {
0646: boolean generate = fGenerateManifestRadioButton.getSelection();
0647:
0648: boolean save = generate && fSaveManifestCheckbox.getSelection();
0649: fSaveManifestCheckbox.setEnabled(generate);
0650: fReuseManifestCheckbox.setEnabled(fJarPackage
0651: .isDescriptionSaved()
0652: && save);
0653: fNewManifestFileText.setEnabled(save);
0654: fNewManifestFileLabel.setEnabled(save);
0655: fNewManifestFileBrowseButton.setEnabled(save);
0656:
0657: fManifestFileText.setEnabled(!generate);
0658: fManifestFileLabel.setEnabled(!generate);
0659: fManifestFileBrowseButton.setEnabled(!generate);
0660:
0661: fSealingHeaderLabel.setEnabled(generate);
0662: boolean sealState = fSealJarRadioButton.getSelection();
0663: fSealJarRadioButton.setEnabled(generate);
0664: fSealJarLabel.setEnabled(generate);
0665: fUnSealedPackagesDetailsButton
0666: .setEnabled(sealState && generate);
0667: fSealPackagesRadioButton.setEnabled(generate);
0668: fSealPackagesLabel.setEnabled(generate);
0669: fSealedPackagesDetailsButton.setEnabled(!sealState && generate);
0670:
0671: fMainClassHeaderLabel.setEnabled(generate);
0672: fMainClassLabel.setEnabled(generate);
0673: fMainClassText.setEnabled(generate);
0674: fMainClassBrowseButton.setEnabled(generate);
0675:
0676: updateSealingInfo();
0677: }
0678:
0679: protected void updateSealingInfo() {
0680: if (fJarPackage.isJarSealed()) {
0681: fSealPackagesLabel.setText(""); //$NON-NLS-1$
0682: int i = fJarPackage.getPackagesToUnseal().length;
0683: if (i == 0)
0684: fSealJarLabel
0685: .setText(JarPackagerMessages.JarManifestWizardPage_jarSealed);
0686: else if (i == 1)
0687: fSealJarLabel
0688: .setText(JarPackagerMessages.JarManifestWizardPage_jarSealedExceptOne);
0689: else
0690: fSealJarLabel
0691: .setText(Messages
0692: .format(
0693: JarPackagerMessages.JarManifestWizardPage_jarSealedExceptSome,
0694: new Integer(i)));
0695:
0696: } else {
0697: fSealJarLabel.setText(""); //$NON-NLS-1$
0698: int i = fJarPackage.getPackagesToSeal().length;
0699: if (i == 0)
0700: fSealPackagesLabel
0701: .setText(JarPackagerMessages.JarManifestWizardPage_nothingSealed);
0702: else if (i == 1)
0703: fSealPackagesLabel
0704: .setText(JarPackagerMessages.JarManifestWizardPage_onePackageSealed);
0705: else
0706: fSealPackagesLabel
0707: .setText(Messages
0708: .format(
0709: JarPackagerMessages.JarManifestWizardPage_somePackagesSealed,
0710: new Integer(i)));
0711: }
0712: }
0713:
0714: /*
0715: * Implements method from IJarPackageWizardPage
0716: */
0717: public boolean isPageComplete() {
0718: boolean isPageComplete = true;
0719: setMessage(null);
0720:
0721: if (!fJarPackage.areGeneratedFilesExported())
0722: return true;
0723:
0724: if (fJarPackage.isManifestGenerated()
0725: && fJarPackage.isManifestSaved()) {
0726: if (fJarPackage.getManifestLocation().toString().length() == 0)
0727: isPageComplete = false;
0728: else {
0729: IPath location = fJarPackage.getManifestLocation();
0730: if (!location.toString().startsWith("/")) { //$NON-NLS-1$
0731: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_manifestPathMustBeAbsolute);
0732: return false;
0733: }
0734: IResource resource = findResource(location);
0735: if (resource != null
0736: && resource.getType() != IResource.FILE) {
0737: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_manifestMustNotBeExistingContainer);
0738: return false;
0739: }
0740: resource = findResource(location.removeLastSegments(1));
0741: if (resource == null
0742: || resource.getType() == IResource.FILE) {
0743: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_manifestContainerDoesNotExist);
0744: return false;
0745: }
0746: }
0747: }
0748: if (!fJarPackage.isManifestGenerated()) {
0749: if (fJarPackage.isManifestAccessible()) {
0750: Manifest manifest = null;
0751: try {
0752: manifest = fJarPackage.getManifestProvider()
0753: .create(fJarPackage);
0754: } catch (CoreException ex) {
0755: // nothing reported in the wizard
0756: }
0757: if (manifest != null
0758: && manifest.getMainAttributes().getValue(
0759: Attributes.Name.MANIFEST_VERSION) == null)
0760: setMessage(
0761: JarPackagerMessages.JarManifestWizardPage_warning_noManifestVersion,
0762: IMessageProvider.WARNING);
0763: } else {
0764: if (fJarPackage.getManifestLocation().toString()
0765: .length() == 0)
0766: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_noManifestFile);
0767: else
0768: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_invalidManifestFile);
0769: return false;
0770: }
0771: }
0772: Set selectedPackages = getPackagesForSelectedResources(fJarPackage);
0773: if (fJarPackage.isJarSealed()
0774: && !selectedPackages.containsAll(Arrays
0775: .asList(fJarPackage.getPackagesToUnseal()))) {
0776: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_unsealedPackagesNotInSelection);
0777: return false;
0778: }
0779: if (!fJarPackage.isJarSealed()
0780: && !selectedPackages.containsAll(Arrays
0781: .asList(fJarPackage.getPackagesToSeal()))) {
0782: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_sealedPackagesNotInSelection);
0783: return false;
0784: }
0785: if (!fJarPackage.isMainClassValid(getContainer())
0786: || (fJarPackage.getManifestMainClass() == null && fMainClassText
0787: .getText().length() > 0)) {
0788: setErrorMessage(JarPackagerMessages.JarManifestWizardPage_error_invalidMainClass);
0789: return false;
0790: }
0791:
0792: setErrorMessage(null);
0793: return isPageComplete;
0794: }
0795:
0796: /*
0797: * Implements method from IWizardPage.
0798: */
0799: public void setPreviousPage(IWizardPage page) {
0800: super .setPreviousPage(page);
0801: fMainTypes = null;
0802: updateEnableState();
0803: if (getContainer() != null)
0804: updatePageCompletion();
0805: }
0806:
0807: /*
0808: * Implements method from IJarPackageWizardPage.
0809: */
0810: public void finish() {
0811: saveWidgetValues();
0812: }
0813:
0814: // ----------- Model handling -----------
0815:
0816: /**
0817: * Persists resource specification control setting that are to be restored
0818: * in the next instance of this page. Subclasses wishing to persist
0819: * settings for their controls should extend the hook method
0820: * <code>internalSaveWidgetValues</code>.
0821: */
0822: public final void saveWidgetValues() {
0823: IDialogSettings settings = getDialogSettings();
0824: if (settings != null) {
0825: // Manifest creation
0826: settings.put(STORE_GENERATE_MANIFEST, fJarPackage
0827: .isManifestGenerated());
0828: settings.put(STORE_SAVE_MANIFEST, fJarPackage
0829: .isManifestSaved());
0830: settings.put(STORE_REUSE_MANIFEST, fJarPackage
0831: .isManifestReused());
0832: settings.put(STORE_MANIFEST_LOCATION, fJarPackage
0833: .getManifestLocation().toString());
0834:
0835: // Sealing
0836: settings.put(STORE_SEAL_JAR, fJarPackage.isJarSealed());
0837: }
0838:
0839: // Allow subclasses to save values
0840: internalSaveWidgetValues();
0841: }
0842:
0843: /**
0844: * Hook method for subclasses to persist their settings.
0845: */
0846: protected void internalSaveWidgetValues() {
0847: }
0848:
0849: /**
0850: * Hook method for restoring widget values to the values that they held
0851: * last time this wizard was used to completion.
0852: */
0853: protected void restoreWidgetValues() {
0854: if (!((JarPackageWizard) getWizard())
0855: .isInitializingFromJarPackage())
0856: initializeJarPackage();
0857:
0858: // Manifest creation
0859: if (fJarPackage.isManifestGenerated())
0860: fGenerateManifestRadioButton.setSelection(true);
0861: else
0862: fUseManifestRadioButton.setSelection(true);
0863: fSaveManifestCheckbox.setSelection(fJarPackage
0864: .isManifestSaved());
0865: fReuseManifestCheckbox.setSelection(fJarPackage
0866: .isManifestReused());
0867: fManifestFileText.setText(fJarPackage.getManifestLocation()
0868: .toString());
0869: fNewManifestFileText.setText(fJarPackage.getManifestLocation()
0870: .toString());
0871:
0872: // Sealing
0873: if (fJarPackage.isJarSealed())
0874: fSealJarRadioButton.setSelection(true);
0875: else
0876: fSealPackagesRadioButton.setSelection(true);
0877:
0878: // Main-Class
0879: fMainClassText.setText(JarPackagerUtil
0880: .getMainClassName(fJarPackage));
0881: }
0882:
0883: /**
0884: * Initializes the JAR package from last used wizard page values.
0885: */
0886: protected void initializeJarPackage() {
0887: IDialogSettings settings = getDialogSettings();
0888: if (settings != null) {
0889: // Manifest creation
0890: fJarPackage.setGenerateManifest(settings
0891: .getBoolean(STORE_GENERATE_MANIFEST));
0892: fJarPackage.setSaveManifest(settings
0893: .getBoolean(STORE_SAVE_MANIFEST));
0894: fJarPackage.setReuseManifest(settings
0895: .getBoolean(STORE_REUSE_MANIFEST));
0896: String pathStr = settings.get(STORE_MANIFEST_LOCATION);
0897: if (pathStr == null)
0898: pathStr = ""; //$NON-NLS-1$
0899: fJarPackage.setManifestLocation(new Path(pathStr));
0900:
0901: // Sealing
0902: fJarPackage.setSealJar(settings.getBoolean(STORE_SEAL_JAR));
0903: }
0904: }
0905:
0906: /**
0907: * Stores the widget values in the JAR package.
0908: */
0909: protected void updateModel() {
0910: if (getControl() == null)
0911: return;
0912:
0913: // Manifest creation
0914: fJarPackage.setGenerateManifest(fGenerateManifestRadioButton
0915: .getSelection());
0916: fJarPackage.setSaveManifest(fSaveManifestCheckbox
0917: .getSelection());
0918: fJarPackage.setReuseManifest(fReuseManifestCheckbox
0919: .getSelection());
0920: String path;
0921: if (fJarPackage.isManifestGenerated())
0922: path = fNewManifestFileText.getText();
0923: else
0924: path = fManifestFileText.getText();
0925: if (path == null)
0926: path = ""; //$NON-NLS-1$
0927: fJarPackage.setManifestLocation(new Path(path));
0928:
0929: // Sealing
0930: fJarPackage.setSealJar(fSealJarRadioButton.getSelection());
0931: }
0932:
0933: /**
0934: * Determine if the page is complete and update the page appropriately.
0935: */
0936: protected void updatePageCompletion() {
0937: boolean pageComplete = isPageComplete();
0938: setPageComplete(pageComplete);
0939: if (pageComplete) {
0940: setErrorMessage(null);
0941: }
0942: }
0943:
0944: // ----------- Utility methods -----------
0945:
0946: /**
0947: * Creates a file resource handle for the file with the given workspace path.
0948: * This method does not create the file resource; this is the responsibility
0949: * of <code>createFile</code>.
0950: *
0951: * @param filePath the path of the file resource to create a handle for
0952: * @return the new file resource handle
0953: */
0954: protected IFile createFileHandle(IPath filePath) {
0955: if (filePath.isValidPath(filePath.toString())
0956: && filePath.segmentCount() >= 2)
0957: return JavaPlugin.getWorkspace().getRoot()
0958: .getFile(filePath);
0959: else
0960: return null;
0961: }
0962:
0963: /**
0964: * Creates a new label with a bold font.
0965: *
0966: * @param parent the parent control
0967: * @param text the label text
0968: * @return the new label control
0969: */
0970: protected Label createLabel(Composite parent, String text,
0971: boolean bold) {
0972: Label label = new Label(parent, SWT.NONE);
0973: if (bold)
0974: label.setFont(JFaceResources.getBannerFont());
0975: label.setText(text);
0976: GridData data = new GridData();
0977: data.verticalAlignment = GridData.FILL;
0978: data.horizontalAlignment = GridData.FILL;
0979: label.setLayoutData(data);
0980: return label;
0981: }
0982:
0983: /**
0984: * Sets the size of a control.
0985: *
0986: * @param control the control for which to set the size
0987: * @param width the new width of the control
0988: * @param height the new height of the control
0989: */
0990: protected void setSize(Control control, int width, int height) {
0991: GridData gd = new GridData(GridData.END);
0992: gd.widthHint = width;
0993: gd.heightHint = height;
0994: control.setLayoutData(gd);
0995: }
0996:
0997: /**
0998: * Makes the size of all buttons equal.
0999: */
1000: protected void setEqualButtonSizes() {
1001: int width = SWTUtil
1002: .getButtonWidthHint(fManifestFileBrowseButton);
1003: int width2 = SWTUtil
1004: .getButtonWidthHint(fNewManifestFileBrowseButton);
1005: width = Math.max(width, width2);
1006:
1007: width2 = SWTUtil
1008: .getButtonWidthHint(fSealedPackagesDetailsButton);
1009: width = Math.max(width, width2);
1010:
1011: width2 = SWTUtil
1012: .getButtonWidthHint(fUnSealedPackagesDetailsButton);
1013: width = Math.max(width, width2);
1014:
1015: width2 = SWTUtil.getButtonWidthHint(fMainClassBrowseButton);
1016: width = Math.max(width, width2);
1017:
1018: setSize(fManifestFileBrowseButton, width, SWT.DEFAULT);
1019: setSize(fNewManifestFileBrowseButton, width, SWT.DEFAULT);
1020: setSize(fSealedPackagesDetailsButton, width, SWT.DEFAULT);
1021: setSize(fUnSealedPackagesDetailsButton, width, SWT.DEFAULT);
1022: setSize(fMainClassBrowseButton, width, SWT.DEFAULT);
1023: }
1024:
1025: /**
1026: * Creates a horizontal spacer line that fills the width of its container.
1027: *
1028: * @param parent the parent control
1029: */
1030: protected void createSpacer(Composite parent) {
1031: Label spacer = new Label(parent, SWT.NONE);
1032: GridData data = new GridData();
1033: data.horizontalAlignment = GridData.FILL;
1034: data.verticalAlignment = GridData.BEGINNING;
1035: spacer.setLayoutData(data);
1036: }
1037:
1038: /**
1039: * Returns the resource for the specified path.
1040: *
1041: * @param path the path for which the resource should be returned
1042: * @return the resource specified by the path or <code>null</code>
1043: */
1044: protected IResource findResource(IPath path) {
1045: IWorkspace workspace = JavaPlugin.getWorkspace();
1046: IStatus result = workspace.validatePath(path.toString(),
1047: IResource.ROOT | IResource.PROJECT | IResource.FOLDER
1048: | IResource.FILE);
1049: if (result.isOK() && workspace.getRoot().exists(path))
1050: return workspace.getRoot().findMember(path);
1051: return null;
1052: }
1053:
1054: protected IPath getPathFromString(String text) {
1055: return new Path(text).makeAbsolute();
1056: }
1057:
1058: /**
1059: * Creates a selection dialog that lists all packages under the given package
1060: * fragment root.
1061: * The caller is responsible for opening the dialog with <code>Window.open</code>,
1062: * and subsequently extracting the selected packages (of type
1063: * <code>IPackageFragment</code>) via <code>SelectionDialog.getResult</code>.
1064: *
1065: * @param packageFragments the package fragments
1066: * @return a new selection dialog
1067: */
1068: protected SelectionDialog createPackageDialog(Set packageFragments) {
1069: List packages = new ArrayList(packageFragments.size());
1070: for (Iterator iter = packageFragments.iterator(); iter
1071: .hasNext();) {
1072: IPackageFragment fragment = (IPackageFragment) iter.next();
1073: boolean containsJavaElements = false;
1074: int kind;
1075: try {
1076: kind = fragment.getKind();
1077: containsJavaElements = fragment.getChildren().length > 0;
1078: } catch (JavaModelException ex) {
1079: ExceptionHandler
1080: .handle(
1081: ex,
1082: getContainer().getShell(),
1083: JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_title,
1084: Messages
1085: .format(
1086: JarPackagerMessages.JarManifestWizardPage_error_jarPackageWizardError_message,
1087: fragment
1088: .getElementName()));
1089: continue;
1090: }
1091: if (kind != IPackageFragmentRoot.K_BINARY
1092: && containsJavaElements)
1093: packages.add(fragment);
1094: }
1095: StandardJavaElementContentProvider cp = new StandardJavaElementContentProvider() {
1096: public boolean hasChildren(Object element) {
1097: // prevent the + from being shown in front of packages
1098: return !(element instanceof IPackageFragment)
1099: && super .hasChildren(element);
1100: }
1101: };
1102: final DecoratingLabelProvider provider = new DecoratingLabelProvider(
1103: new JavaElementLabelProvider(
1104: JavaElementLabelProvider.SHOW_DEFAULT),
1105: new ProblemsLabelDecorator(null));
1106: ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
1107: getContainer().getShell(), provider, cp);
1108: dialog.setDoubleClickSelects(false);
1109: dialog.setComparator(new JavaElementComparator());
1110: dialog.setInput(JavaCore.create(JavaPlugin.getWorkspace()
1111: .getRoot()));
1112: dialog.addFilter(new EmptyInnerPackageFilter());
1113: dialog.addFilter(new LibraryFilter());
1114: dialog.addFilter(new SealPackagesFilter(packages));
1115: dialog.setValidator(new ISelectionStatusValidator() {
1116: public IStatus validate(Object[] selection) {
1117: StatusInfo res = new StatusInfo();
1118: for (int i = 0; i < selection.length; i++) {
1119: if (!(selection[i] instanceof IPackageFragment)) {
1120: res
1121: .setError(JarPackagerMessages.JarManifestWizardPage_error_mustContainPackages);
1122: return res;
1123: }
1124: }
1125: res.setOK();
1126: return res;
1127: }
1128: });
1129: return dialog;
1130: }
1131:
1132: /**
1133: * Converts selection dialog results into an array of IPackageFragments.
1134: * An empty array is returned in case of errors.
1135: * @throws ClassCastException if results are not IPackageFragments
1136: */
1137: protected IPackageFragment[] getPackagesFromDialog(
1138: SelectionDialog dialog) {
1139: if (dialog.getReturnCode() == Window.OK
1140: && dialog.getResult().length > 0)
1141: return (IPackageFragment[]) Arrays.asList(
1142: dialog.getResult()).toArray(
1143: new IPackageFragment[dialog.getResult().length]);
1144: else
1145: return new IPackageFragment[0];
1146: }
1147:
1148: /**
1149: * Creates and returns a dialog to choose an existing workspace file.
1150: */
1151: protected ElementTreeSelectionDialog createWorkspaceFileSelectionDialog(
1152: String title, String message) {
1153: int labelFlags = JavaElementLabelProvider.SHOW_BASICS
1154: | JavaElementLabelProvider.SHOW_OVERLAY_ICONS
1155: | JavaElementLabelProvider.SHOW_SMALL_ICONS;
1156: final DecoratingLabelProvider provider = new DecoratingLabelProvider(
1157: new JavaElementLabelProvider(labelFlags),
1158: new ProblemsLabelDecorator(null));
1159: ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
1160: getShell(), provider,
1161: new StandardJavaElementContentProvider());
1162: dialog.setComparator(new JavaElementComparator());
1163: dialog.setAllowMultiple(false);
1164: dialog.setValidator(new ISelectionStatusValidator() {
1165: public IStatus validate(Object[] selection) {
1166: StatusInfo res = new StatusInfo();
1167: // only single selection
1168: if (selection.length == 1
1169: && (selection[0] instanceof IFile))
1170: res.setOK();
1171: else
1172: res.setError(""); //$NON-NLS-1$
1173: return res;
1174: }
1175: });
1176: dialog.addFilter(new EmptyInnerPackageFilter());
1177: dialog.addFilter(new LibraryFilter());
1178: dialog.setTitle(title);
1179: dialog.setMessage(message);
1180: dialog.setStatusLineAboveButtons(true);
1181: dialog.setInput(JavaCore.create(JavaPlugin.getWorkspace()
1182: .getRoot()));
1183: return dialog;
1184: }
1185:
1186: /**
1187: * Returns the minimal set of packages which contain all the selected Java resources.
1188: * @return the Set of IPackageFragments which contain all the selected resources
1189: */
1190: private Set getPackagesForSelectedResources(
1191: JarPackageData jarPackage) {
1192: Set packages = new HashSet();
1193: int n = fJarPackage.getElements().length;
1194: for (int i = 0; i < n; i++) {
1195: Object element = fJarPackage.getElements()[i];
1196: if (element instanceof ICompilationUnit) {
1197: packages.add(((ICompilationUnit) element).getParent());
1198: }
1199: }
1200: return packages;
1201: }
1202: }
|