Source Code Cross Referenced for RuntimeInfoSection.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » build » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.ui.editor.build 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.pde.internal.ui.editor.build;
0011:
0012:        import java.util.ArrayList;
0013:        import java.util.HashSet;
0014:        import java.util.Iterator;
0015:        import java.util.Set;
0016:        import java.util.Vector;
0017:
0018:        import org.eclipse.core.resources.IFile;
0019:        import org.eclipse.core.resources.IFolder;
0020:        import org.eclipse.core.resources.IProject;
0021:        import org.eclipse.core.resources.IResource;
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:        import org.eclipse.core.runtime.Status;
0027:        import org.eclipse.jdt.core.IClasspathEntry;
0028:        import org.eclipse.jdt.core.IJavaProject;
0029:        import org.eclipse.jdt.core.IPackageFragmentRoot;
0030:        import org.eclipse.jdt.core.JavaCore;
0031:        import org.eclipse.jdt.core.JavaModelException;
0032:        import org.eclipse.jface.action.Action;
0033:        import org.eclipse.jface.action.IAction;
0034:        import org.eclipse.jface.action.IMenuListener;
0035:        import org.eclipse.jface.action.IMenuManager;
0036:        import org.eclipse.jface.action.MenuManager;
0037:        import org.eclipse.jface.action.Separator;
0038:        import org.eclipse.jface.dialogs.IInputValidator;
0039:        import org.eclipse.jface.viewers.ISelection;
0040:        import org.eclipse.jface.viewers.IStructuredContentProvider;
0041:        import org.eclipse.jface.viewers.IStructuredSelection;
0042:        import org.eclipse.jface.viewers.ITableLabelProvider;
0043:        import org.eclipse.jface.viewers.LabelProvider;
0044:        import org.eclipse.jface.viewers.StructuredSelection;
0045:        import org.eclipse.jface.viewers.TableViewer;
0046:        import org.eclipse.jface.viewers.Viewer;
0047:        import org.eclipse.jface.viewers.ViewerFilter;
0048:        import org.eclipse.jface.window.Window;
0049:        import org.eclipse.pde.core.IBaseModel;
0050:        import org.eclipse.pde.core.IEditable;
0051:        import org.eclipse.pde.core.IModelChangedEvent;
0052:        import org.eclipse.pde.core.IModelChangedListener;
0053:        import org.eclipse.pde.core.build.IBuild;
0054:        import org.eclipse.pde.core.build.IBuildEntry;
0055:        import org.eclipse.pde.core.build.IBuildModel;
0056:        import org.eclipse.pde.core.plugin.IPluginModelBase;
0057:        import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
0058:        import org.eclipse.pde.internal.ui.PDELabelProvider;
0059:        import org.eclipse.pde.internal.ui.PDEPlugin;
0060:        import org.eclipse.pde.internal.ui.PDEPluginImages;
0061:        import org.eclipse.pde.internal.ui.PDEUIMessages;
0062:        import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
0063:        import org.eclipse.pde.internal.ui.editor.PDEFormPage;
0064:        import org.eclipse.pde.internal.ui.editor.PDESection;
0065:        import org.eclipse.pde.internal.ui.editor.context.InputContext;
0066:        import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
0067:        import org.eclipse.pde.internal.ui.parts.StructuredViewerPart;
0068:        import org.eclipse.pde.internal.ui.parts.TablePart;
0069:        import org.eclipse.pde.internal.ui.wizards.FolderSelectionDialog;
0070:        import org.eclipse.pde.internal.ui.wizards.RenameDialog;
0071:        import org.eclipse.swt.SWT;
0072:        import org.eclipse.swt.custom.BusyIndicator;
0073:        import org.eclipse.swt.graphics.Image;
0074:        import org.eclipse.swt.layout.GridData;
0075:        import org.eclipse.swt.widgets.Button;
0076:        import org.eclipse.swt.widgets.Composite;
0077:        import org.eclipse.swt.widgets.Table;
0078:        import org.eclipse.ui.ISharedImages;
0079:        import org.eclipse.ui.PlatformUI;
0080:        import org.eclipse.ui.actions.ActionFactory;
0081:        import org.eclipse.ui.dialogs.ISelectionStatusValidator;
0082:        import org.eclipse.ui.forms.widgets.FormToolkit;
0083:        import org.eclipse.ui.forms.widgets.Section;
0084:        import org.eclipse.ui.model.WorkbenchContentProvider;
0085:        import org.eclipse.ui.model.WorkbenchLabelProvider;
0086:
0087:        public class RuntimeInfoSection extends PDESection implements 
0088:                IModelChangedListener, IBuildPropertiesConstants {
0089:
0090:            private static final int F_NEW_INDEX = 0;
0091:            private static final int F_UP_UNDEX = 2;
0092:            private static final int F_DOWN_INDEX = 3;
0093:
0094:            protected TableViewer fLibraryViewer;
0095:            protected TableViewer fFolderViewer;
0096:
0097:            protected StructuredViewerPart fLibraryPart;
0098:            protected StructuredViewerPart fFolderPart;
0099:
0100:            private boolean fEnabled = true;
0101:
0102:            class PartAdapter extends TablePart {
0103:
0104:                public PartAdapter(String[] buttonLabels) {
0105:                    super (buttonLabels);
0106:                }
0107:
0108:                public void selectionChanged(IStructuredSelection selection) {
0109:                    getPage().getPDEEditor().setSelection(selection);
0110:                    Object item = selection.getFirstElement();
0111:                    if (item instanceof  IBuildEntry) {
0112:                        update((IBuildEntry) item);
0113:                    } else if (selection == null || selection.isEmpty())
0114:                        update(null);
0115:                    updateDirectionalButtons();
0116:                }
0117:
0118:                public void handleDoubleClick(IStructuredSelection selection) {
0119:                    Object element = selection.getFirstElement();
0120:                    if (getLibrarySelection() == element)
0121:                        doRename();
0122:                    else if (element instanceof  String)
0123:                        handleRenameFolder((String) element);
0124:                }
0125:
0126:                public void buttonSelected(Button button, int index) {
0127:                    if (getViewer() == fLibraryPart.getViewer()) {
0128:                        switch (index) {
0129:                        case F_NEW_INDEX:
0130:                            handleNew();
0131:                            break;
0132:                        case F_UP_UNDEX: // move up
0133:                            updateJarsCompileOrder(true);
0134:                            break;
0135:                        case F_DOWN_INDEX: // move down
0136:                            updateJarsCompileOrder(false);
0137:                            break;
0138:                        }
0139:                    } else if (getViewer() == fFolderPart.getViewer()
0140:                            && index == F_NEW_INDEX)
0141:                        handleNewFolder();
0142:                    else
0143:                        button.getShell().setDefaultButton(null);
0144:                }
0145:            }
0146:
0147:            public class LibraryContentProvider extends DefaultContentProvider
0148:                    implements  IStructuredContentProvider {
0149:
0150:                public Object[] getElements(Object parent) {
0151:                    if (parent instanceof  IBuildModel) {
0152:                        IBuild build = ((IBuildModel) parent).getBuild();
0153:                        IBuildEntry jarOrderEntry = build
0154:                                .getEntry(PROPERTY_JAR_ORDER);
0155:                        IBuildEntry[] libraries = BuildUtil
0156:                                .getBuildLibraries(build.getBuildEntries());
0157:                        if (jarOrderEntry == null)
0158:                            return libraries;
0159:
0160:                        Vector libList = new Vector();
0161:                        String[] tokens = jarOrderEntry.getTokens();
0162:                        for (int i = 0; i < tokens.length; i++) {
0163:                            IBuildEntry entry = build
0164:                                    .getEntry(IBuildEntry.JAR_PREFIX
0165:                                            + tokens[i]);
0166:                            if (entry != null)
0167:                                libList.add(entry);
0168:                        }
0169:                        for (int i = 0; i < libraries.length; i++)
0170:                            if (!libList.contains(libraries[i]))
0171:                                libList.add(libraries[i]);
0172:                        return libList.toArray();
0173:                    }
0174:                    return new Object[0];
0175:                }
0176:            }
0177:
0178:            public class LibraryLabelProvider extends LabelProvider implements 
0179:                    ITableLabelProvider {
0180:                public String getColumnText(Object obj, int index) {
0181:                    String name = ((IBuildEntry) obj).getName();
0182:                    if (name.startsWith(IBuildEntry.JAR_PREFIX))
0183:                        return name.substring(IBuildEntry.JAR_PREFIX.length());
0184:                    return name;
0185:                }
0186:
0187:                public Image getColumnImage(Object obj, int index) {
0188:                    PDELabelProvider provider = PDEPlugin.getDefault()
0189:                            .getLabelProvider();
0190:                    return provider.get(PDEPluginImages.DESC_JAVA_LIB_OBJ);
0191:                }
0192:            }
0193:
0194:            class JarsNewContentProvider extends WorkbenchContentProvider {
0195:                public boolean hasChildren(Object element) {
0196:                    Object[] children = getChildren(element);
0197:                    for (int i = 0; i < children.length; i++)
0198:                        if (children[i] instanceof  IFolder)
0199:                            return true;
0200:                    return false;
0201:                }
0202:            }
0203:
0204:            public class FolderContentProvider extends DefaultContentProvider
0205:                    implements  IStructuredContentProvider {
0206:                public Object[] getElements(Object parent) {
0207:                    return (parent instanceof  IBuildEntry) ? ((IBuildEntry) parent)
0208:                            .getTokens()
0209:                            : new Object[0];
0210:                }
0211:            }
0212:
0213:            public class FolderLabelProvider extends LabelProvider implements 
0214:                    ITableLabelProvider {
0215:                public String getColumnText(Object obj, int index) {
0216:                    return obj.toString();
0217:                }
0218:
0219:                public Image getColumnImage(Object obj, int index) {
0220:                    ISharedImages sharedImages = PlatformUI.getWorkbench()
0221:                            .getSharedImages();
0222:                    return sharedImages.getImage(ISharedImages.IMG_OBJ_FOLDER);
0223:                }
0224:            }
0225:
0226:            public RuntimeInfoSection(PDEFormPage page, Composite parent) {
0227:                super (page, parent, Section.DESCRIPTION);
0228:                getSection().setText(
0229:                        PDEUIMessages.BuildEditor_RuntimeInfoSection_title);
0230:                getSection().setDescription(
0231:                        PDEUIMessages.BuildEditor_RuntimeInfoSection_desc);
0232:                getBuildModel().addModelChangedListener(this );
0233:                createClient(getSection(), page.getManagedForm().getToolkit());
0234:            }
0235:
0236:            private IBuildModel getBuildModel() {
0237:                InputContext context = getPage().getPDEEditor()
0238:                        .getContextManager().findContext(
0239:                                BuildInputContext.CONTEXT_ID);
0240:                if (context == null)
0241:                    return null;
0242:                return (IBuildModel) context.getModel();
0243:            }
0244:
0245:            protected void handleLibInBinBuild(boolean isSelected,
0246:                    String libName) {
0247:                IBuildModel model = getBuildModel();
0248:                IBuildEntry binIncl = model.getBuild().getEntry(
0249:                        PROPERTY_BIN_INCLUDES);
0250:                IProject project = model.getUnderlyingResource().getProject();
0251:                IPath libPath;
0252:                if (libName.equals(".")) //$NON-NLS-1$
0253:                    libPath = null;
0254:                else
0255:                    libPath = project.getFile(libName).getProjectRelativePath();
0256:                try {
0257:                    if (binIncl == null && !isSelected)
0258:                        return;
0259:                    if (binIncl == null) {
0260:                        binIncl = model.getFactory().createEntry(
0261:                                PROPERTY_BIN_INCLUDES);
0262:                        model.getBuild().add(binIncl);
0263:                    }
0264:                    if (libPath != null) {
0265:                        if (!isSelected && libPath.segmentCount() == 1
0266:                                && binIncl.contains("*.jar")) { //$NON-NLS-1$
0267:                            addAllJarsToBinIncludes(binIncl, project, model);
0268:                        } else if (!isSelected && libPath.segmentCount() > 1) {
0269:                            IPath parent = libPath.removeLastSegments(1);
0270:                            String parentPath = parent.toString()
0271:                                    + IPath.SEPARATOR;
0272:                            if (binIncl.contains(parentPath)
0273:                                    && !project.exists(parent)) {
0274:                                binIncl.removeToken(parentPath);
0275:                            } else if (parent.segmentCount() > 1) {
0276:                                parent = parent.removeLastSegments(1);
0277:                                parentPath = parent.toString()
0278:                                        + IPath.SEPARATOR;
0279:                                if (binIncl.contains(parentPath)
0280:                                        && !project.exists(parent))
0281:                                    binIncl.removeToken(parentPath);
0282:                            }
0283:                        }
0284:                    }
0285:                    if (isSelected && !binIncl.contains(libName))
0286:                        binIncl.addToken(libName);
0287:                    else if (!isSelected && binIncl.contains(libName))
0288:                        binIncl.removeToken(libName);
0289:                } catch (CoreException e) {
0290:                    PDEPlugin.logException(e);
0291:                }
0292:
0293:            }
0294:
0295:            protected void addAllJarsToBinIncludes(IBuildEntry binIncl,
0296:                    IProject project, IBuildModel model) {
0297:                try {
0298:                    IResource[] members = project.members();
0299:                    for (int i = 0; i < members.length; i++)
0300:                        if (!(members[i] instanceof  IFolder)
0301:                                && members[i].getFileExtension().equals("jar")) //$NON-NLS-1$
0302:                            binIncl.addToken(members[i].getName());
0303:
0304:                    IBuildEntry[] libraries = BuildUtil.getBuildLibraries(model
0305:                            .getBuild().getBuildEntries());
0306:                    if (libraries.length != 0) {
0307:                        for (int j = 0; j < libraries.length; j++) {
0308:                            String libraryName = libraries[j].getName()
0309:                                    .substring(7);
0310:                            IPath path = project.getFile(libraryName)
0311:                                    .getProjectRelativePath();
0312:                            if (path.segmentCount() == 1
0313:                                    && !binIncl.contains(libraryName))
0314:                                binIncl.addToken(libraryName);
0315:                        }
0316:                    }
0317:                    binIncl.removeToken("*.jar"); //$NON-NLS-1$
0318:                } catch (CoreException e) {
0319:                    PDEPlugin.logException(e);
0320:                }
0321:            }
0322:
0323:            private void setOutputEntryTokens(Set outputFolders,
0324:                    IBuildEntry outputEntry) {
0325:                Iterator iter = outputFolders.iterator();
0326:                try {
0327:                    while (iter.hasNext()) {
0328:                        String outputFolder = iter.next().toString();
0329:                        if (!outputFolder.endsWith("" + IPath.SEPARATOR)) //$NON-NLS-1$
0330:                            outputFolder = outputFolder
0331:                                    .concat("" + IPath.SEPARATOR); //$NON-NLS-1$
0332:                        if (!outputEntry.contains(outputFolder.toString()))
0333:                            outputEntry.addToken(outputFolder.toString());
0334:                    }
0335:                } catch (CoreException e) {
0336:                    PDEPlugin.logException(e);
0337:                }
0338:            }
0339:
0340:            private IPackageFragmentRoot[] computeSourceFolders() {
0341:                ArrayList folders = new ArrayList();
0342:                IBuildModel buildModel = getBuildModel();
0343:                IProject project = buildModel.getUnderlyingResource()
0344:                        .getProject();
0345:                try {
0346:                    if (project.hasNature(JavaCore.NATURE_ID)) {
0347:                        IJavaProject jProject = JavaCore.create(project);
0348:                        IPackageFragmentRoot[] roots = jProject
0349:                                .getPackageFragmentRoots();
0350:                        for (int i = 0; i < roots.length; i++)
0351:                            if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE)
0352:                                folders.add(roots[i]);
0353:                    }
0354:                } catch (JavaModelException e) {
0355:                    PDEPlugin.logException(e);
0356:                } catch (CoreException e) {
0357:                    PDEPlugin.logException(e);
0358:                }
0359:                return (IPackageFragmentRoot[]) folders
0360:                        .toArray(new IPackageFragmentRoot[folders.size()]);
0361:            }
0362:
0363:            public void createClient(Section section, FormToolkit toolkit) {
0364:                Composite container = toolkit.createComposite(section);
0365:                container.setLayout(FormLayoutFactory
0366:                        .createSectionClientGridLayout(false, 2));
0367:
0368:                createLeftSection(container, toolkit);
0369:                createRightSection(container, toolkit);
0370:
0371:                toolkit.paintBordersFor(container);
0372:                section.setLayout(FormLayoutFactory.createClearGridLayout(
0373:                        false, 1));
0374:                GridData data = new GridData(GridData.FILL_HORIZONTAL);
0375:                data.horizontalSpan = 2;
0376:                section.setLayoutData(data);
0377:                section.setClient(container);
0378:            }
0379:
0380:            private void createLeftSection(Composite parent, FormToolkit toolkit) {
0381:                Composite container = createContainer(parent, toolkit);
0382:
0383:                fLibraryPart = new PartAdapter(
0384:                        new String[] {
0385:                                PDEUIMessages.BuildEditor_RuntimeInfoSection_addLibrary,
0386:                                null,
0387:                                PDEUIMessages.ManifestEditor_LibrarySection_up,
0388:                                PDEUIMessages.ManifestEditor_LibrarySection_down });
0389:                fLibraryPart.createControl(container, SWT.FULL_SELECTION, 2,
0390:                        toolkit);
0391:                fLibraryViewer = (TableViewer) fLibraryPart.getViewer();
0392:                fLibraryViewer.setContentProvider(new LibraryContentProvider());
0393:                fLibraryViewer.setLabelProvider(new LibraryLabelProvider());
0394:                fLibraryPart.setButtonEnabled(F_UP_UNDEX, false);
0395:                fLibraryPart.setButtonEnabled(F_DOWN_INDEX, false);
0396:                fLibraryViewer.setInput(getBuildModel());
0397:                toolkit.paintBordersFor(container);
0398:
0399:                MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
0400:                menuMgr.setRemoveAllWhenShown(true);
0401:                menuMgr.addMenuListener(new IMenuListener() {
0402:                    public void menuAboutToShow(IMenuManager manager) {
0403:                        fillLibraryContextMenu(manager);
0404:                    }
0405:                });
0406:                fLibraryViewer.getControl().setMenu(
0407:                        menuMgr.createContextMenu(fLibraryViewer.getControl()));
0408:            }
0409:
0410:            private void createRightSection(Composite parent,
0411:                    FormToolkit toolkit) {
0412:                Composite container = createContainer(parent, toolkit);
0413:
0414:                fFolderPart = new PartAdapter(
0415:                        new String[] { PDEUIMessages.BuildEditor_RuntimeInfoSection_addFolder }) {
0416:                    public void selectionChanged(IStructuredSelection selection) {
0417:                        // folder selection ignored
0418:                    }
0419:                };
0420:                fFolderPart.createControl(container, SWT.FULL_SELECTION, 2,
0421:                        toolkit);
0422:                fFolderViewer = (TableViewer) fFolderPart.getViewer();
0423:                fFolderViewer.setContentProvider(new FolderContentProvider());
0424:                fFolderViewer.setLabelProvider(new FolderLabelProvider());
0425:                toolkit.paintBordersFor(container);
0426:
0427:                MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
0428:                menuMgr.setRemoveAllWhenShown(true);
0429:                menuMgr.addMenuListener(new IMenuListener() {
0430:                    public void menuAboutToShow(IMenuManager manager) {
0431:                        fillFolderViewerContextMenu(manager);
0432:                    }
0433:                });
0434:                fFolderViewer.getControl().setMenu(
0435:                        menuMgr.createContextMenu(fFolderViewer.getControl()));
0436:            }
0437:
0438:            private Composite createContainer(Composite parent,
0439:                    FormToolkit toolkit) {
0440:                Composite container = toolkit.createComposite(parent);
0441:                container.setLayout(FormLayoutFactory
0442:                        .createSectionClientGridLayout(false, 2));
0443:                GridData gd = new GridData(GridData.FILL_BOTH);
0444:                gd.widthHint = 100;
0445:                container.setLayoutData(gd);
0446:                return container;
0447:            }
0448:
0449:            protected void fillFolderViewerContextMenu(IMenuManager manager) {
0450:                final ISelection selection = fFolderViewer.getSelection();
0451:                ISelection libSelection = fLibraryViewer.getSelection();
0452:                if (libSelection != null && !libSelection.isEmpty()) {
0453:                    Action newAction = new Action(
0454:                            PDEUIMessages.BuildEditor_RuntimeInfoSection_popupFolder) {
0455:                        public void run() {
0456:                            handleNewFolder();
0457:                        }
0458:                    };
0459:                    newAction.setEnabled(fEnabled);
0460:                    manager.add(newAction);
0461:                }
0462:
0463:                manager.add(new Separator());
0464:
0465:                Action replace = new Action(
0466:                        PDEUIMessages.RuntimeInfoSection_replace) {
0467:                    public void run() {
0468:                        handleRenameFolder(((IStructuredSelection) selection)
0469:                                .getFirstElement().toString());
0470:                    }
0471:                };
0472:                replace.setEnabled(!selection.isEmpty() && fEnabled);
0473:                manager.add(replace);
0474:
0475:                Action deleteAction = new Action(
0476:                        PDEUIMessages.Actions_delete_label) {
0477:                    public void run() {
0478:                        handleDeleteFolder();
0479:                    }
0480:                };
0481:                deleteAction.setEnabled(!selection.isEmpty() && fEnabled);
0482:                manager.add(deleteAction);
0483:
0484:                // defect 19550
0485:                getPage().getPDEEditor().getContributor()
0486:                        .contextMenuAboutToShow(manager, false);
0487:            }
0488:
0489:            protected void fillLibraryContextMenu(IMenuManager manager) {
0490:                ISelection selection = fLibraryViewer.getSelection();
0491:                Action newAction = new Action(
0492:                        PDEUIMessages.BuildEditor_RuntimeInfoSection_popupAdd) {
0493:                    public void run() {
0494:                        handleNew();
0495:                    }
0496:                };
0497:                newAction.setEnabled(fEnabled);
0498:                manager.add(newAction);
0499:
0500:                manager.add(new Separator());
0501:                IAction renameAction = new Action(
0502:                        PDEUIMessages.EditableTablePart_renameAction) {
0503:                    public void run() {
0504:                        doRename();
0505:                    }
0506:                };
0507:                renameAction.setEnabled(!selection.isEmpty() && fEnabled);
0508:                manager.add(renameAction);
0509:
0510:                Action deleteAction = new Action(
0511:                        PDEUIMessages.Actions_delete_label) {
0512:                    public void run() {
0513:                        handleDelete();
0514:                    }
0515:                };
0516:                deleteAction.setEnabled(!selection.isEmpty() && fEnabled);
0517:                manager.add(deleteAction);
0518:
0519:                getPage().getPDEEditor().getContributor()
0520:                        .contextMenuAboutToShow(manager, false);
0521:            }
0522:
0523:            protected void entryModified(IBuildEntry oldEntry, String newValue) {
0524:                final IBuildEntry entry = oldEntry;
0525:                IBuildModel buildModel = getBuildModel();
0526:                IBuild build = buildModel.getBuild();
0527:                String oldName = entry.getName().substring(7);
0528:
0529:                try {
0530:                    if (newValue.equals(entry.getName()))
0531:                        return;
0532:                    if (!newValue.startsWith(IBuildEntry.JAR_PREFIX))
0533:                        newValue = IBuildEntry.JAR_PREFIX + newValue;
0534:                    if (!newValue.endsWith(".jar") && //$NON-NLS-1$
0535:                            !newValue.endsWith("/") && //$NON-NLS-1$
0536:                            !newValue.equals(IBuildEntry.JAR_PREFIX + ".")) //$NON-NLS-1$
0537:                        newValue += "/"; //$NON-NLS-1$
0538:
0539:                    String newName = newValue.substring(7);
0540:
0541:                    // jars.compile.order
0542:                    IBuildEntry tempEntry = build.getEntry(PROPERTY_JAR_ORDER);
0543:                    if (tempEntry != null && tempEntry.contains(oldName))
0544:                        tempEntry.renameToken(oldName, newName);
0545:
0546:                    // output.{source folder}.jar
0547:                    tempEntry = build
0548:                            .getEntry(PROPERTY_OUTPUT_PREFIX + oldName);
0549:                    if (tempEntry != null)
0550:                        tempEntry.setName(PROPERTY_OUTPUT_PREFIX + newName);
0551:
0552:                    // bin.includes
0553:                    tempEntry = build.getEntry(PROPERTY_BIN_INCLUDES);
0554:                    if (tempEntry != null && tempEntry.contains(oldName))
0555:                        tempEntry.renameToken(oldName, newName);
0556:
0557:                    // bin.excludes
0558:                    tempEntry = build.getEntry(PROPERTY_BIN_EXCLUDES);
0559:                    if (tempEntry != null && tempEntry.contains(oldName))
0560:                        tempEntry.renameToken(oldName, newName);
0561:
0562:                    // rename
0563:                    entry.setName(newValue);
0564:
0565:                } catch (CoreException e) {
0566:                    PDEPlugin.logException(e);
0567:                }
0568:            }
0569:
0570:            public void enableSection(boolean enable) {
0571:                fEnabled = enable;
0572:                fLibraryPart.setButtonEnabled(F_NEW_INDEX, enable);
0573:                updateDirectionalButtons();
0574:                fFolderPart.setButtonEnabled(F_NEW_INDEX, enable
0575:                        && !fLibraryViewer.getSelection().isEmpty());
0576:            }
0577:
0578:            public boolean doGlobalAction(String actionId) {
0579:                if (actionId.equals(ActionFactory.DELETE.getId())) {
0580:                    if (fEnabled
0581:                            && fLibraryViewer.getControl().isFocusControl())
0582:                        handleDelete();
0583:                    else if (fEnabled)
0584:                        handleDeleteFolder();
0585:                    return true;
0586:                }
0587:                return false;
0588:            }
0589:
0590:            private void doRename() {
0591:                IStructuredSelection selection = (IStructuredSelection) fLibraryViewer
0592:                        .getSelection();
0593:                if (selection.size() == 1) {
0594:                    IBuildEntry entry = (IBuildEntry) selection
0595:                            .getFirstElement();
0596:                    String oldName = entry.getName().substring(7);
0597:                    RenameDialog dialog = new RenameDialog(fLibraryViewer
0598:                            .getControl().getShell(), true, getLibraryNames(),
0599:                            oldName);
0600:                    dialog.setInputValidator(new IInputValidator() {
0601:                        public String isValid(String newText) {
0602:                            if (newText.indexOf(' ') != -1)
0603:                                return PDEUIMessages.AddLibraryDialog_nospaces;
0604:                            return null;
0605:                        }
0606:                    });
0607:                    dialog.create();
0608:                    dialog.setTitle(PDEUIMessages.RuntimeInfoSection_rename);
0609:                    dialog.getShell().setSize(300, 150);
0610:                    if (dialog.open() == Window.OK)
0611:                        entryModified(entry, dialog.getNewName());
0612:                }
0613:            }
0614:
0615:            public void dispose() {
0616:                IBuildModel buildModel = getBuildModel();
0617:                if (buildModel != null)
0618:                    buildModel.removeModelChangedListener(this );
0619:                super .dispose();
0620:            }
0621:
0622:            private void refreshOutputKeys() {
0623:                if (!isJavaProject())
0624:                    return;
0625:
0626:                IBuildEntry buildEntry = getLibrarySelection();
0627:                if (buildEntry == null)
0628:                    return;
0629:                Set outputFolders = new HashSet();
0630:                String[] jarFolders = buildEntry.getTokens();
0631:                IPackageFragmentRoot[] sourceFolders = computeSourceFolders();
0632:                for (int j = 0; j < jarFolders.length; j++) {
0633:                    IPackageFragmentRoot sourceFolder = getSourceFolder(
0634:                            jarFolders[j], sourceFolders);
0635:                    if (sourceFolder != null) {
0636:                        try {
0637:                            IClasspathEntry entry = sourceFolder
0638:                                    .getRawClasspathEntry();
0639:                            IPath outputPath = entry.getOutputLocation();
0640:                            if (outputPath == null) {
0641:                                outputFolders.add("bin"); //$NON-NLS-1$
0642:                            } else {
0643:                                outputPath = outputPath.removeFirstSegments(1);
0644:                                outputFolders.add(outputPath.toString());
0645:                            }
0646:                        } catch (JavaModelException e) {
0647:                            PDEPlugin.logException(e);
0648:                        }
0649:                    }
0650:                }
0651:                if (outputFolders.size() != 0) {
0652:                    String libName = buildEntry.getName().substring(7);
0653:                    IBuildModel buildModel = getBuildModel();
0654:                    IBuild build = buildModel.getBuild();
0655:                    String outputName = PROPERTY_OUTPUT_PREFIX + libName;
0656:
0657:                    IBuildEntry outputEntry = build.getEntry(outputName);
0658:                    if (outputEntry == null) {
0659:                        outputEntry = buildModel.getFactory().createEntry(
0660:                                outputName);
0661:                        try {
0662:                            build.add(outputEntry);
0663:                        } catch (CoreException e) {
0664:                            PDEPlugin.logException(e);
0665:                        }
0666:                    }
0667:                    setOutputEntryTokens(outputFolders, outputEntry);
0668:                }
0669:            }
0670:
0671:            private boolean isJavaProject() {
0672:                try {
0673:                    IBuildModel buildModel = getBuildModel();
0674:                    IProject project = buildModel.getUnderlyingResource()
0675:                            .getProject();
0676:                    return project.hasNature(JavaCore.NATURE_ID);
0677:                } catch (CoreException e) {
0678:                }
0679:                return false;
0680:            }
0681:
0682:            private boolean isReadOnly() {
0683:                IBuildModel model = getBuildModel();
0684:                if (model instanceof  IEditable)
0685:                    return !((IEditable) model).isEditable();
0686:                return true;
0687:            }
0688:
0689:            private void update(IBuildEntry variable) {
0690:                int index = 0;
0691:                if (fFolderViewer.getInput() == variable)
0692:                    index = fFolderViewer.getTable().getSelectionIndex();
0693:
0694:                fFolderViewer.setInput(variable);
0695:                int count = fFolderViewer.getTable().getItemCount();
0696:                if (index != -1 && count > 0) {
0697:                    if (index == count)
0698:                        index = index - 1;
0699:                    fFolderViewer.getTable().select(index);
0700:                }
0701:                fFolderPart.setButtonEnabled(F_NEW_INDEX, !isReadOnly()
0702:                        && fEnabled && variable != null);
0703:            }
0704:
0705:            protected void updateDirectionalButtons() {
0706:                Table table = fLibraryViewer.getTable();
0707:                boolean hasSelection = table.getSelection().length > 0;
0708:                fLibraryPart.setButtonEnabled(F_UP_UNDEX, fEnabled
0709:                        && hasSelection && table.getSelectionIndex() > 0);
0710:                fLibraryPart
0711:                        .setButtonEnabled(F_DOWN_INDEX, fEnabled
0712:                                && hasSelection
0713:                                && table.getSelectionIndex() < table
0714:                                        .getItemCount() - 1);
0715:            }
0716:
0717:            protected String[] getLibraryNames() {
0718:                String[] libNames = new String[fLibraryViewer.getTable()
0719:                        .getItemCount()];
0720:                for (int i = 0; i < libNames.length; i++)
0721:                    libNames[i] = fLibraryViewer.getTable().getItem(i)
0722:                            .getText();
0723:                return libNames;
0724:            }
0725:
0726:            protected void handleNew() {
0727:                final String[] libNames = getLibraryNames();
0728:                IBaseModel pmodel = getPage().getModel();
0729:                final IPluginModelBase pluginModelBase = (pmodel instanceof  IPluginModelBase) ? (IPluginModelBase) pmodel
0730:                        : null;
0731:
0732:                BusyIndicator.showWhile(fLibraryViewer.getTable().getDisplay(),
0733:                        new Runnable() {
0734:                            public void run() {
0735:                                IBuildModel buildModel = getBuildModel();
0736:                                IBuild build = buildModel.getBuild();
0737:                                AddLibraryDialog dialog = new AddLibraryDialog(
0738:                                        getSection().getShell(), libNames,
0739:                                        pluginModelBase);
0740:                                dialog.create();
0741:                                dialog
0742:                                        .getShell()
0743:                                        .setText(
0744:                                                PDEUIMessages.RuntimeInfoSection_addEntry);
0745:
0746:                                try {
0747:                                    if (dialog.open() == Window.OK) {
0748:                                        String name = dialog.getNewName();
0749:                                        if (!name.endsWith(".jar") //$NON-NLS-1$
0750:                                                && !name.equals(".") //$NON-NLS-1$
0751:                                                && !name.endsWith("/")) //$NON-NLS-1$
0752:                                            name += "/"; //$NON-NLS-1$
0753:
0754:                                        String keyName = name;
0755:                                        if (!keyName
0756:                                                .startsWith(IBuildEntry.JAR_PREFIX))
0757:                                            keyName = IBuildEntry.JAR_PREFIX
0758:                                                    + name;
0759:                                        if (name
0760:                                                .startsWith(IBuildEntry.JAR_PREFIX))
0761:                                            name = name.substring(7);
0762:
0763:                                        if (!name.endsWith(".")) //$NON-NLS-1$
0764:                                            handleLibInBinBuild(true, name);
0765:
0766:                                        // add library to jars compile order
0767:                                        IBuildEntry jarOrderEntry = build
0768:                                                .getEntry(PROPERTY_JAR_ORDER);
0769:                                        int numLib = fLibraryViewer.getTable()
0770:                                                .getItemCount();
0771:
0772:                                        if (jarOrderEntry == null) {
0773:                                            jarOrderEntry = getBuildModel()
0774:                                                    .getFactory().createEntry(
0775:                                                            PROPERTY_JAR_ORDER);
0776:
0777:                                            // add all runtime libraries to compile order
0778:                                            for (int i = 0; i < numLib; i++) {
0779:                                                String lib = ((IBuildEntry) fLibraryViewer
0780:                                                        .getElementAt(i))
0781:                                                        .getName().substring(7);
0782:                                                jarOrderEntry.addToken(lib);
0783:                                            }
0784:                                            jarOrderEntry.addToken(name);
0785:                                            build.add(jarOrderEntry);
0786:                                        } else if (jarOrderEntry.getTokens().length < numLib) {
0787:
0788:                                            // remove and re-add all runtime libraries to compile order
0789:                                            String[] tokens = jarOrderEntry
0790:                                                    .getTokens();
0791:                                            for (int i = 0; i < tokens.length; i++)
0792:                                                jarOrderEntry
0793:                                                        .removeToken(tokens[i]);
0794:
0795:                                            for (int i = 0; i < numLib; i++) {
0796:                                                String lib = ((IBuildEntry) fLibraryViewer
0797:                                                        .getElementAt(i))
0798:                                                        .getName().substring(7);
0799:                                                jarOrderEntry.addToken(lib);
0800:                                            }
0801:                                            jarOrderEntry.addToken(name);
0802:                                        } else {
0803:                                            jarOrderEntry.addToken(name);
0804:                                        }
0805:                                        // end of jars compile order addition
0806:
0807:                                        IBuildEntry library = buildModel
0808:                                                .getFactory().createEntry(
0809:                                                        keyName);
0810:                                        build.add(library);
0811:
0812:                                    }
0813:                                } catch (CoreException e) {
0814:                                    PDEPlugin.logException(e);
0815:                                }
0816:                            }
0817:                        });
0818:            }
0819:
0820:            private IPackageFragmentRoot getSourceFolder(String folderName,
0821:                    IPackageFragmentRoot[] sourceFolders) {
0822:                for (int i = 0; i < sourceFolders.length; i++)
0823:                    if (sourceFolders[i].getPath().removeFirstSegments(1)
0824:                            .equals(new Path(folderName)))
0825:                        return sourceFolders[i];
0826:                return null;
0827:            }
0828:
0829:            protected void handleDelete() {
0830:                int index = fLibraryViewer.getTable().getSelectionIndex();
0831:                if (index != -1) {
0832:                    String libName = fLibraryViewer.getTable().getItem(index)
0833:                            .getText();
0834:                    IBuild build = getBuildModel().getBuild();
0835:
0836:                    try {
0837:                        // jars.compile.order
0838:                        IBuildEntry entry = build.getEntry(PROPERTY_JAR_ORDER);
0839:                        int numLib = fLibraryViewer.getTable().getItemCount();
0840:
0841:                        if (entry == null) {
0842:                            entry = getBuildModel().getFactory().createEntry(
0843:                                    PROPERTY_JAR_ORDER);
0844:
0845:                            // add all runtime libraries to compile order
0846:                            for (int i = 0; i < numLib; i++) {
0847:                                String lib = ((IBuildEntry) fLibraryViewer
0848:                                        .getElementAt(i)).getName()
0849:                                        .substring(7);
0850:                                entry.addToken(lib);
0851:                            }
0852:                            build.add(entry);
0853:                        } else if (entry.getTokens().length < numLib) {
0854:
0855:                            // remove and re-add all runtime libraries to compile order
0856:                            String[] tokens = entry.getTokens();
0857:                            for (int i = 0; i < tokens.length; i++)
0858:                                entry.removeToken(tokens[i]);
0859:
0860:                            for (int i = 0; i < numLib; i++) {
0861:                                Object element = fLibraryViewer.getElementAt(i);
0862:                                if (element == null) {
0863:                                    continue;
0864:                                }
0865:                                String lib = ((IBuildEntry) element).getName()
0866:                                        .substring(7);
0867:                                entry.addToken(lib);
0868:                            }
0869:                        }
0870:
0871:                        entry.removeToken(libName);
0872:
0873:                        // output.{source folder}.jar
0874:                        entry = build
0875:                                .getEntry(PROPERTY_OUTPUT_PREFIX + libName);
0876:                        if (entry != null)
0877:                            build.remove(entry);
0878:
0879:                        // bin.includes
0880:                        entry = build.getEntry(PROPERTY_BIN_INCLUDES);
0881:                        if (entry != null && entry.contains(libName))
0882:                            entry.removeToken(libName);
0883:
0884:                        // bin.excludes
0885:                        entry = build.getEntry(PROPERTY_BIN_EXCLUDES);
0886:                        if (entry != null && entry.contains(libName))
0887:                            entry.removeToken(libName);
0888:
0889:                        String entryName = IBuildEntry.JAR_PREFIX + libName;
0890:                        entry = build.getEntry(entryName);
0891:                        if (entry != null) {
0892:                            build.remove(entry);
0893:                        }
0894:                    } catch (CoreException e) {
0895:                        PDEPlugin.logException(e);
0896:                    }
0897:                }
0898:            }
0899:
0900:            private void handleDeleteFolder() {
0901:                Object object = ((IStructuredSelection) fFolderViewer
0902:                        .getSelection()).getFirstElement();
0903:                if (object == null)
0904:                    return;
0905:                IBuildEntry entry = getLibrarySelection();
0906:                if (entry == null)
0907:                    return;
0908:                try {
0909:                    entry.removeToken((String) object);
0910:                } catch (CoreException e) {
0911:                    PDEPlugin.logException(e);
0912:                }
0913:            }
0914:
0915:            private IFolder openSelectFolderDialog(final IBuildEntry entry,
0916:                    String title, String message) {
0917:                IFile file = (IFile) getBuildModel().getUnderlyingResource();
0918:                final IProject project = file.getProject();
0919:
0920:                FolderSelectionDialog dialog = new FolderSelectionDialog(
0921:                        PDEPlugin.getActiveWorkbenchShell(),
0922:                        new WorkbenchLabelProvider(),
0923:                        new JarsNewContentProvider() {
0924:                        });
0925:
0926:                dialog.setInput(project.getWorkspace());
0927:                dialog.addFilter(new ViewerFilter() {
0928:                    public boolean select(Viewer viewer, Object parentElement,
0929:                            Object element) {
0930:                        if (element instanceof  IProject)
0931:                            return ((IProject) element).equals(project);
0932:                        return element instanceof  IFolder;
0933:                    }
0934:                });
0935:                dialog.setAllowMultiple(false);
0936:                dialog.setTitle(title);
0937:                dialog.setMessage(message);
0938:
0939:                dialog.setValidator(new ISelectionStatusValidator() {
0940:                    public IStatus validate(Object[] selection) {
0941:                        String id = PDEPlugin.getPluginId();
0942:                        if (selection == null || selection.length != 1
0943:                                || !(selection[0] instanceof  IFolder))
0944:                            return new Status(IStatus.ERROR, id, IStatus.ERROR,
0945:                                    "", null); //$NON-NLS-1$
0946:
0947:                        String folderPath = ((IFolder) selection[0])
0948:                                .getProjectRelativePath()
0949:                                .addTrailingSeparator().toString();
0950:                        if (entry != null && entry.contains(folderPath))
0951:                            return new Status(
0952:                                    IStatus.ERROR,
0953:                                    id,
0954:                                    IStatus.ERROR,
0955:                                    PDEUIMessages.BuildEditor_RuntimeInfoSection_duplicateFolder,
0956:                                    null);
0957:
0958:                        return new Status(IStatus.OK, id, IStatus.OK, "", null); //$NON-NLS-1$
0959:                    }
0960:                });
0961:
0962:                if (dialog.open() == Window.OK)
0963:                    return (IFolder) dialog.getFirstResult();
0964:                return null;
0965:            }
0966:
0967:            private void handleNewFolder() {
0968:                IBuildEntry entry = getLibrarySelection();
0969:                IFolder folder = openSelectFolderDialog(entry,
0970:                        PDEUIMessages.ManifestEditor_JarsSection_dialogTitle,
0971:                        PDEUIMessages.ManifestEditor_JarsSection_dialogMessage);
0972:                if (folder != null) {
0973:                    try {
0974:                        String folderPath = folder.getProjectRelativePath()
0975:                                .addTrailingSeparator().toString();
0976:                        entry.addToken(folderPath);
0977:                        refreshOutputKeys();
0978:                    } catch (CoreException e) {
0979:                        PDEPlugin.logException(e);
0980:                    }
0981:                }
0982:            }
0983:
0984:            private void handleRenameFolder(String oldName) {
0985:                IBuildEntry entry = getLibrarySelection();
0986:                IFolder folder = openSelectFolderDialog(entry,
0987:                        PDEUIMessages.RuntimeInfoSection_replacedialog,
0988:                        PDEUIMessages.ManifestEditor_JarsSection_dialogMessage);
0989:                if (folder != null) {
0990:                    try {
0991:                        String newFolder = folder.getProjectRelativePath()
0992:                                .addTrailingSeparator().toString();
0993:                        entry.renameToken(oldName, newFolder);
0994:                        refreshOutputKeys();
0995:                    } catch (CoreException e) {
0996:                        PDEPlugin.logException(e);
0997:                    }
0998:                }
0999:            }
1000:
1001:            protected void updateJarsCompileOrder(boolean up) {
1002:                int direction = up ? -1 : 1;
1003:                int index = fLibraryViewer.getTable().getSelectionIndex();
1004:                String library1 = ((IBuildEntry) fLibraryViewer
1005:                        .getElementAt(index)).getName().substring(7);
1006:                String library2 = ((IBuildEntry) fLibraryViewer
1007:                        .getElementAt(index + direction)).getName()
1008:                        .substring(7);
1009:
1010:                IBuildModel model = getBuildModel();
1011:                IBuild build = model.getBuild();
1012:                IBuildEntry jarOrderEntry = build.getEntry(PROPERTY_JAR_ORDER);
1013:                try {
1014:                    if (jarOrderEntry == null) {
1015:                        jarOrderEntry = model.getFactory().createEntry(
1016:                                PROPERTY_JAR_ORDER);
1017:                        build.add(jarOrderEntry);
1018:                    } else {
1019:                        String tokens[] = jarOrderEntry.getTokens();
1020:                        for (int i = 0; i < tokens.length; i++)
1021:                            jarOrderEntry.removeToken(tokens[i]);
1022:                    }
1023:
1024:                    int numLib = fLibraryViewer.getTable().getItemCount();
1025:                    String[] names = new String[numLib];
1026:                    for (int i = 0; i < numLib; i++) {
1027:                        String name = ((IBuildEntry) fLibraryViewer
1028:                                .getElementAt(i)).getName().substring(7);
1029:                        if (name.equals(library1))
1030:                            name = library2;
1031:                        else if (name.equals(library2))
1032:                            name = library1;
1033:                        names[i] = name;
1034:                    }
1035:
1036:                    for (int i = 0; i < numLib; i++)
1037:                        jarOrderEntry.addToken(names[i]);
1038:
1039:                } catch (CoreException e) {
1040:                    PDEPlugin.logException(e);
1041:                }
1042:            }
1043:
1044:            public void modelChanged(IModelChangedEvent event) {
1045:                if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED)
1046:                    markStale();
1047:                Object changeObject = event.getChangedObjects()[0];
1048:                String keyName = event.getChangedProperty();
1049:
1050:                // check if model change applies to this section
1051:                if (!(changeObject instanceof  IBuildEntry))
1052:                    return;
1053:                IBuildEntry entry = (IBuildEntry) changeObject;
1054:                String entryName = entry.getName();
1055:                if (!entryName.startsWith(IBuildEntry.JAR_PREFIX)
1056:                        && !entryName.equals(PROPERTY_JAR_ORDER)
1057:                        && !entryName.equals(PROPERTY_BIN_INCLUDES))
1058:                    return;
1059:
1060:                if (entryName.equals(PROPERTY_BIN_INCLUDES))
1061:                    return;
1062:
1063:                int type = event.getChangeType();
1064:
1065:                // account for new key
1066:                if (entry.getName().startsWith(PROPERTY_SOURCE_PREFIX)) {
1067:                    IStructuredSelection newSel = null;
1068:                    if (type == IModelChangedEvent.INSERT) {
1069:                        fLibraryViewer.add(entry);
1070:                        newSel = new StructuredSelection(entry);
1071:                    } else if (type == IModelChangedEvent.REMOVE) {
1072:                        int index = fLibraryViewer.getTable()
1073:                                .getSelectionIndex();
1074:                        fLibraryViewer.remove(entry);
1075:                        Table table = fLibraryViewer.getTable();
1076:                        int itemCount = table.getItemCount();
1077:                        if (itemCount != 0) {
1078:                            index = index < itemCount ? index : itemCount - 1;
1079:                            newSel = new StructuredSelection(table.getItem(
1080:                                    index).getData());
1081:                        }
1082:                    } else if (keyName != null
1083:                            && keyName.startsWith(IBuildEntry.JAR_PREFIX)) {
1084:                        // modification to source.{libname}.jar
1085:                        if (event.getOldValue() != null
1086:                                && event.getNewValue() != null)
1087:                            // renaming token
1088:                            fLibraryViewer.update(entry, null);
1089:
1090:                        newSel = new StructuredSelection(entry);
1091:                    }
1092:                    fLibraryViewer.setSelection(newSel);
1093:                } else if (keyName != null
1094:                        && keyName.equals(PROPERTY_JAR_ORDER)) {
1095:                    // account for change in jars compile order
1096:                    if (event.getNewValue() == null
1097:                            && event.getOldValue() != null)
1098:                        // removing token from jars compile order : do nothing
1099:                        return;
1100:                    if (event.getOldValue() != null
1101:                            && event.getNewValue() != null)
1102:                        // renaming token from jars compile order : do nothing
1103:                        return;
1104:
1105:                    fLibraryViewer.refresh();
1106:                    updateDirectionalButtons();
1107:                }
1108:            }
1109:
1110:            private IBuildEntry getLibrarySelection() {
1111:                IStructuredSelection selection = (IStructuredSelection) fLibraryViewer
1112:                        .getSelection();
1113:                return (IBuildEntry) selection.getFirstElement();
1114:            }
1115:        }
w_w__w___.j__a___v___a__2__s_._c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.