1 11 package org.eclipse.pde.internal.ui.editor.product; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.jface.dialogs.MessageDialog; 18 import org.eclipse.pde.core.IBaseModel; 19 import org.eclipse.pde.internal.core.iproduct.IProduct; 20 import org.eclipse.pde.internal.core.iproduct.IProductModel; 21 import org.eclipse.pde.internal.ui.IHelpContextIds; 22 import org.eclipse.pde.internal.ui.IPDEUIConstants; 23 import org.eclipse.pde.internal.ui.PDELabelProvider; 24 import org.eclipse.pde.internal.ui.PDEPlugin; 25 import org.eclipse.pde.internal.ui.PDEPluginImages; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; 28 import org.eclipse.pde.internal.ui.editor.LaunchShortcutOverviewPage; 29 import org.eclipse.pde.internal.ui.wizards.product.SynchronizationOperation; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.ui.PlatformUI; 32 import org.eclipse.ui.forms.IManagedForm; 33 import org.eclipse.ui.forms.editor.FormEditor; 34 import org.eclipse.ui.forms.events.HyperlinkEvent; 35 import org.eclipse.ui.forms.widgets.FormText; 36 import org.eclipse.ui.forms.widgets.FormToolkit; 37 import org.eclipse.ui.forms.widgets.ScrolledForm; 38 import org.eclipse.ui.forms.widgets.Section; 39 import org.eclipse.ui.progress.IProgressService; 40 41 42 public class OverviewPage extends LaunchShortcutOverviewPage { 43 44 public static final String PAGE_ID = "overview"; 46 public OverviewPage(FormEditor editor) { 47 super(editor, PAGE_ID, PDEUIMessages.OverviewPage_title); 48 } 49 50 53 protected String getHelpResource() { 54 return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/product_editor/overview.htm"; } 56 57 60 protected void createFormContent(IManagedForm managedForm) { 61 super.createFormContent(managedForm); 62 ScrolledForm form = managedForm.getForm(); 63 FormToolkit toolkit = managedForm.getToolkit(); 64 form.setText(PDEUIMessages.OverviewPage_title); 65 form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PRODUCT_DEFINITION)); 66 fillBody(managedForm, toolkit); 67 PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.OVERVIEW_PAGE); 68 } 69 70 private void fillBody(IManagedForm managedForm, FormToolkit toolkit) { 71 Composite body = managedForm.getForm().getBody(); 72 body.setLayout(FormLayoutFactory.createFormTableWrapLayout(true, 2)); 73 74 ProductInfoSection section = new ProductInfoSection(this, body); 75 76 managedForm.addPart(section); 77 if (getModel().isEditable()) { 78 createTestingSection(body, toolkit); 79 createExportingSection(body, toolkit); 80 } 81 } 82 83 private void createTestingSection(Composite parent, FormToolkit toolkit) { 84 Section section = createStaticSection(toolkit, parent, PDEUIMessages.Product_OverviewPage_testing); 85 FormText text = createClient(section, getLauncherText(false, PDEUIMessages.Product_overview_testing), toolkit); 86 PDELabelProvider lp = PDEPlugin.getDefault().getLabelProvider(); 87 text.setImage("run", lp.get(PDEPluginImages.DESC_RUN_EXC)); text.setImage("debug", lp.get(PDEPluginImages.DESC_DEBUG_EXC)); text.setImage("profile", lp.get(PDEPluginImages.DESC_PROFILE_EXC)); section.setClient(text); 91 } 92 93 private void createExportingSection(Composite parent, FormToolkit toolkit) { 94 Section section = createStaticSection(toolkit, parent, PDEUIMessages.OverviewPage_exportingTitle); 95 section.setClient(createClient(section, PDEUIMessages.Product_overview_exporting, toolkit)); 96 } 97 98 public void linkActivated(HyperlinkEvent e) { 99 String href = (String ) e.getHref(); 100 if (href.equals("action.synchronize")) { handleSynchronize(true); 102 } else if (href.equals("action.export")) { if (getPDEEditor().isDirty()) 104 getPDEEditor().doSave(null); 105 new ProductExportAction(getPDEEditor()).run(); 106 } else if (href.equals("configuration")) { String pageId = getProduct().useFeatures() ? ConfigurationPage.FEATURE_ID : ConfigurationPage.PLUGIN_ID; 108 getEditor().setActivePage(pageId); 109 } else 110 super.linkActivated(e); 111 } 112 113 protected Object getLaunchObject() { 114 Object file = getEditorInput().getAdapter(IFile.class); 115 if (file != null) 116 return file; 117 return ((IProductModel)getPDEEditor().getAggregateModel()).getUnderlyingResource(); 118 } 119 120 protected void preLaunch() { 121 handleSynchronize(false); 122 } 123 124 private void handleSynchronize(boolean alert) { 125 try { 126 IProgressService service = PlatformUI.getWorkbench().getProgressService(); 127 IProject project = getPDEEditor().getCommonProject(); 128 SynchronizationOperation op = new SynchronizationOperation(getProduct(), getSite().getShell(), project); 129 service.runInUI(service, op, PDEPlugin.getWorkspace().getRoot()); 130 } catch (InterruptedException e) { 131 } catch (InvocationTargetException e) { 132 if (alert) MessageDialog.openError(getSite().getShell(), "Synchronize", e.getTargetException().getMessage()); } 134 } 135 136 private IProduct getProduct() { 137 IBaseModel model = getPDEEditor().getAggregateModel(); 138 return ((IProductModel)model).getProduct(); 139 } 140 141 protected short getIndent() { 142 return 35; 143 } 144 145 } 146 | Popular Tags |