/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.pages;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import net.java.dev.genesis.annotation.ViewHandler;
import net.java.dev.genesis.ui.swt.SWTBinder;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.forms.HyperlinkGroup;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.ColumnLayout;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ImageHyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.SWTBotIDs;
import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.EditableTableControl;
import de.innovationgate.eclipse.utils.ui.GenesisBoundFormPage;
import de.innovationgate.eclipse.utils.ui.SingleStructuredSelection;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.eclipse.wgadesigner.ExternalResourceIDs;
import de.innovationgate.eclipse.wgadesigner.ResourceIDs;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.actions.OpenContentManager;
import de.innovationgate.eclipse.wgadesigner.actions.OpenWGAAdminPage;
import de.innovationgate.eclipse.wgadesigner.actions.RestartWGARuntime;
import de.innovationgate.eclipse.wgadesigner.actions.StartWGARuntime;
import de.innovationgate.eclipse.wgadesigner.actions.StopWGARuntime;
import de.innovationgate.eclipse.wgadesigner.models.WGARuntimeConfigurationModel;
import de.innovationgate.eclipse.wgadesigner.models.WebApplication;
import de.innovationgate.eclipse.wgadesigner.models.WebApplicationsModel;
import de.innovationgate.eclipse.wgadesigner.natures.IncompatibleWGAConfigVersion;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntimeListener;
import de.innovationgate.eclipse.wgadesigner.tomcat.TomcatServerStateListener;
import de.innovationgate.eclipse.wgadesigner.tomcat.TomcatUtils;
import de.innovationgate.wga.config.ContentStore;
import de.innovationgate.wga.config.WGAConfiguration;
import de.innovationgate.wga.model.Model;
@ViewHandler
public class WGARuntimeStatusPage extends GenesisBoundFormPage implements TomcatServerStateListener, WGARuntimeListener {
public static final String ID = "de.innovationgate.eclipse.wgadesigner.wgaruntimeeditor.pages.WGARuntimeStatusPage";
public static final String PAGE_TITLE = "Status";
private WGARuntimeConfigurationModel _model;
private Button _btnStartRuntime;
private Button _btnStopRuntime;
private Label _lblState;
private Hyperlink _linkOpenAdminPage;
private EditableTableControl<WebApplication> _tblWebApplications;
private ImageHyperlink _linkCreateWebApp;
private WebApplicationsModel _webAppModel;
private Section _webAppSection;
// private MenuItem _itemOpenInBrowser;
// private MenuItem _itemOpenInContentManager;
// private MenuItem _itemOpenInAdminClient;
// private MenuItem _itemOpenInDesignEditor;
private Button _btnRestartRuntime;
private WGADesignStructureHelper _helper;
public WGARuntimeStatusPage(FormEditor editor) {
super(editor, ID, PAGE_TITLE);
}
public void setModel(Model model) {
_model = (WGARuntimeConfigurationModel) model;
}
public Model getModel() {
return _model;
}
@Override
protected void createFormContent(IManagedForm managedForm) {
ScrolledForm form = managedForm.getForm();
FormToolkit toolkit = managedForm.getToolkit();
toolkit.decorateFormHeading(form.getForm());
form.setText(PAGE_TITLE);
ColumnLayout layout = new ColumnLayout();
layout.maxNumColumns = 1;
form.getBody().setLayout(layout);
// management section
Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
section.setText("Management");
Composite sectionClient = toolkit.createComposite(section);
section.setClient(sectionClient);
GridLayout sectionLayout = new GridLayout();
sectionLayout.numColumns = 2;
sectionClient.setLayout(sectionLayout);
Label lblStateDesc = new Label(sectionClient, SWT.NONE);
lblStateDesc.setText("State:");
_lblState = new Label(sectionClient, SWT.NONE);
Composite buttonGroup = toolkit.createComposite(sectionClient);
GridLayout buttonGroupLayout = new GridLayout();
buttonGroupLayout.numColumns = 3;
buttonGroup.setLayout(buttonGroupLayout);
GridData buttonGroupLayoutData = new GridData();
buttonGroupLayoutData.horizontalSpan = 2;
buttonGroup.setLayoutData(buttonGroupLayoutData);
_btnStartRuntime = new Button(buttonGroup, SWT.PUSH);
_btnStartRuntime.setData(SWTBotIDs.WIDGET_KEY, ResourceIDs.SWTBOT_WGARUNTIME_EDITOR_BUTTON_START);
_btnStartRuntime.setText("Start");
_btnStartRuntime.setImage(WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_SERVER_START));
_btnStartRuntime.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
StartWGARuntime.call(_model.getWgaRuntime());
//_btnStartRuntime.setEnabled(false);
} catch (Exception ex) {
}
}
});
_btnStopRuntime = new Button(buttonGroup, SWT.PUSH);
_btnStopRuntime.setText("Stop");
_btnStopRuntime.setData(SWTBotIDs.WIDGET_KEY, ResourceIDs.SWTBOT_WGARUNTIME_EDITOR_BUTTON_STOP);
_btnStopRuntime.setImage(WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_SERVER_STOP));
_btnStopRuntime.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
StopWGARuntime.call();
//_btnStopRuntime.setEnabled(false);
} catch (Exception ex) {
}
}
});
_btnRestartRuntime = new Button(buttonGroup, SWT.PUSH);
_btnRestartRuntime.setText("Restart");
_btnRestartRuntime.setImage(WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_SERVER_RESTART));
_btnRestartRuntime.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
RestartWGARuntime.call();
} catch (Exception ex) {
}
}
});
HyperlinkGroup group = new HyperlinkGroup(sectionClient.getDisplay());
_linkOpenAdminPage = new Hyperlink(sectionClient, SWT.NONE);
_linkOpenAdminPage.setText("Open Admin Page");
_linkOpenAdminPage.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
OpenWGAAdminPage.call(_model.getWgaRuntime());
}
});
Label filler = new Label(sectionClient, SWT.NONE);
// _linkOpenContentManager = new Hyperlink(sectionClient, SWT.NONE);
// _linkOpenContentManager.setText("Open Content Manager");
// _linkOpenContentManager.addHyperlinkListener(new HyperlinkAdapter() {
// @Override
// public void linkActivated(HyperlinkEvent e) {
// OpenContentManager.call(_model.getWgaRuntime());
// }
// });
group.add(_linkOpenAdminPage);
TomcatUtils.getInstance().addListener(this);
//group.add(_linkOpenContentManager);
// web app section
_webAppSection = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
_webAppSection.setText("Web Applications");
List<WebApplication> apps = retrieveWebApplications();
WGAConfiguration config = null;
try {
config = _model.getWgaRuntime().retrieveWGAConfig(false);
} catch (Exception e2) {
WGADesignerPlugin.getDefault().logError("Unable to read wga configuration." , e2);
}
_webAppModel = new WebApplicationsModel(apps, config);
// register as runtime listener to refresh web app model on wga config changes
_model.getWgaRuntime().addListener(this);
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
ToolBar toolbar = toolBarManager.createControl(_webAppSection);
Action action1 = new Action("refresh", WGADesignerPlugin.getDefault().getImageRegistry().getDescriptor(WGADesignerPlugin.IMAGE_REFRESH)) {
public void run() {
refreshWebApplications();
}
};
toolBarManager.add(action1);
toolBarManager.update(true);
_webAppSection.setTextClient(toolbar);
sectionClient = toolkit.createComposite(_webAppSection);
_webAppSection.setClient(sectionClient);
sectionLayout = new GridLayout();
sectionLayout.verticalSpacing =0;
sectionLayout.numColumns = 2;
sectionClient.setLayout(sectionLayout);
HyperlinkGroup generalHyperLinkGroup = new HyperlinkGroup(sectionClient.getDisplay());
_linkCreateWebApp = new ImageHyperlink(sectionClient, SWT.NONE);
_linkCreateWebApp.setText("Create new web application");
_linkCreateWebApp.setImage(WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_WGA_DESIGN_ADD));
_linkCreateWebApp.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
try {
WorkbenchUtils.openWizard(WGADesignerPlugin.getDefault().getWorkbench(), ResourceIDs.WIZARD_NEW_WGA_DESIGN, new SingleStructuredSelection(_model.getWgaRuntime().getProject()));
} catch (CoreException e1) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to open wizard 'New WGADesign'", e1);
}
}
});
generalHyperLinkGroup.add(_linkCreateWebApp);
filler = new Label(sectionClient, SWT.NONE);
_tblWebApplications = new EditableTableControl<WebApplication>(sectionClient, SWT.NONE,SWT.BORDER|SWT.FULL_SELECTION) {
@Override
protected boolean isButtonAreaNeeded() {
return false;
}
};
GridData tblGridData = new GridData(GridData.FILL_BOTH);
tblGridData.minimumHeight = 200;
tblGridData.verticalSpan = 5;
_tblWebApplications.setLayoutData(tblGridData);
String[] columnNames = new String[] { "Key", "Title", "Domain", "Design" };
_tblWebApplications.init(columnNames, _webAppModel);
Composite tableActionsContainer = new Composite(sectionClient, SWT.NONE);
tableActionsContainer.setLayout(new GridLayout(1, false));
tableActionsContainer.setLayoutData(new GridData(SWT.BEGINNING));
GridData linkGridData = new GridData(SWT.BEGINNING);
linkGridData.verticalAlignment = SWT.TOP;
Label lblOpenIn = new Label(tableActionsContainer, SWT.NONE);
lblOpenIn.setLayoutData(GridDataFactory.copyData(linkGridData));
lblOpenIn.setText("open selected web application in ...");
Hyperlink openInBrowser = new Hyperlink(tableActionsContainer, SWT.NONE);
openInBrowser.setLayoutData(GridDataFactory.copyData(linkGridData));
openInBrowser.setText("Browser");
openInBrowser.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
handleOpenInBrowser();
}
});
Hyperlink openInDesignEditor = new Hyperlink(tableActionsContainer, SWT.NONE);
openInDesignEditor.setLayoutData(GridDataFactory.copyData(linkGridData));
openInDesignEditor.setText("Design Editor");
openInDesignEditor.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
handleOpenInDesignEditor();
}
});
Hyperlink openInContentManager = new Hyperlink(tableActionsContainer, SWT.NONE);
openInContentManager.setLayoutData(GridDataFactory.copyData(linkGridData));
openInContentManager.setText("Content Manager");
openInContentManager.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
handleOpenInContentManager();
}
});
Hyperlink openInAdminClient = new Hyperlink(tableActionsContainer, SWT.NONE);
openInAdminClient.setLayoutData(GridDataFactory.copyData(linkGridData));
openInAdminClient.setText("Admin Client");
openInAdminClient.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
handleOpenInAdminClient();
}
});
generalHyperLinkGroup.add(openInBrowser);
generalHyperLinkGroup.add(openInDesignEditor);
generalHyperLinkGroup.add(openInContentManager);
generalHyperLinkGroup.add(openInAdminClient);
Label seperator = new Label(tableActionsContainer, SWT.SEPARATOR | SWT.HORIZONTAL);
seperator.setLayoutData(new GridData(SWT.FILL));
ImageHyperlink exportWebApplication = new ImageHyperlink(tableActionsContainer, SWT.NONE);
exportWebApplication.setText("Export web application");
exportWebApplication.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
handleExportWebApplication();
}
});
exportWebApplication.setImage(WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_EXPORT_WGA_DESIGN));
generalHyperLinkGroup.add(exportWebApplication);
/*
Menu webApplicationsPopup = new Menu(_tblWebApplications.getTable());
_tblWebApplications.getTable().setMenu(webApplicationsPopup);
_itemOpenInBrowser = new MenuItem(webApplicationsPopup, SWT.PUSH);
_itemOpenInBrowser.setText("open in Browser");
_itemOpenInBrowser.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleOpenInBrowser();
}
});
_itemOpenInDesignEditor = new MenuItem(webApplicationsPopup, SWT.PUSH);
_itemOpenInDesignEditor.setText("open in Design Editor");
_itemOpenInDesignEditor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
WorkbenchUtils.openEditor(Plugin.getDefault().getWorkbench(), _helper.getSyncInfo(), ExternalResourceIDs.EDITOR_WGA_DESIGN);
} catch (Exception e1) {
MessageDialog.openError(getSite().getShell(), "Error", "Unable to Design Editor. See log for details.");
WGADesignerPlugin.getDefault().logError("Unable to Design Editor.", e1);
}
}
}
});
_itemOpenInContentManager = new MenuItem(webApplicationsPopup, SWT.PUSH);
_itemOpenInContentManager.setText("open in Content Manager");
_itemOpenInContentManager.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
IWebBrowser browser = WGADesignerPlugin.getDefault().createBrowser(OpenContentManager.BROWSER_ID);
browser.openURL(_model.getWgaRuntime().getContentManagerURL(app.getContentStore()));
} catch (PartInitException e1) {
MessageDialog.openError(getSite().getShell(), "Error", "Unable to open content manager. See log for details.");
WGADesignerPlugin.getDefault().logError("Unable to open content manager.", e1);
}
}
}
});
_itemOpenInAdminClient = new MenuItem(webApplicationsPopup, SWT.PUSH);
_itemOpenInAdminClient.setText("open in Admin Client");
_itemOpenInAdminClient.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
IWebBrowser browser = WGADesignerPlugin.getDefault().createBrowser(OpenContentManager.BROWSER_ID);
browser.openURL(_model.getWgaRuntime().getAdminClientURL(app.getContentStore()));
} catch (PartInitException e1) {
MessageDialog.openError(getSite().getShell(), "Error", "Unable to open admin client. See log for details.");
WGADesignerPlugin.getDefault().logError("Unable to open admin client.", e1);
}
}
}
});
_tblWebApplications.getTable().addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
Map<String, IContainer> connectedDesigns;
try {
connectedDesigns = _model.getWgaRuntime().getConnectedDesignContainers();
IContainer design = connectedDesigns.get(app.getContentStore().getKey());
if(design!=null&&design.exists()){
_itemOpenInDesignEditor.setEnabled(true);
_helper = new WGADesignStructureHelper(design);
}
else{
_itemOpenInDesignEditor.setEnabled(false);
}
} catch (IncompatibleWGAConfigVersion e1) {
_itemOpenInDesignEditor.setEnabled(false);
} catch (IOException e1) {
_itemOpenInDesignEditor.setEnabled(false);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
*/
_tblWebApplications.getTable().addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseDoubleClick(MouseEvent e) {
handleOpenInBrowser();
}
});
bind(form, SWTBinder.BINDING_STRATEGY_AS_YOU_TYPE);
}
private List<WebApplication> retrieveWebApplications() {
List<WebApplication> apps = new ArrayList<WebApplication>();
WGAConfiguration config;
try {
config = _model.getWgaRuntime().retrieveWGAConfig(false);
if (config != null) {
for (ContentStore cs : config.getContentStores()) {
WebApplication webApplication = new WebApplication();
webApplication.setRuntime(_model.getWgaRuntime());
webApplication.setContentStore(cs);
apps.add(webApplication);
}
}
} catch (Exception e) {
WGADesignerPlugin.getDefault().logError("Unable to create web application model.", e);
}
Collections.sort(apps, new Comparator<WebApplication>() {
public int compare(WebApplication o1, WebApplication o2) {
String key1 = "";
String key2 = "";
if (o1 != null && o1.getContentStore() != null && o1.getContentStore().getKey() != null) {
key1 = o1.getContentStore().getKey();
}
if (o2 != null && o2.getContentStore() != null && o2.getContentStore().getKey() != null) {
key2 = o2.getContentStore().getKey();
}
return key1.compareTo(key2);
}
});
return apps;
}
public void stateChanged(int state) {
if (state == TomcatServerStateListener.STATE_RUNNING && TomcatUtils.getInstance().isRunning(_model.getWgaRuntime())) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
_btnStartRuntime.setEnabled(false);
_btnRestartRuntime.setEnabled(true);
_lblState.setText("running");
_btnStopRuntime.setEnabled(true);
_linkOpenAdminPage.setEnabled(true);
// _itemOpenInAdminClient.setEnabled(true);
// _itemOpenInBrowser.setEnabled(true);
// _itemOpenInContentManager.setEnabled(true);
_lblState.pack();
}
});
} else if (state == TomcatServerStateListener.STATE_STARTING) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
_btnStartRuntime.setEnabled(false);
_btnRestartRuntime.setEnabled(false);
_lblState.setText("starting");
_btnStopRuntime.setEnabled(false);
_linkOpenAdminPage.setEnabled(false);
// _itemOpenInAdminClient.setEnabled(false);
// _itemOpenInBrowser.setEnabled(false);
// _itemOpenInContentManager.setEnabled(false);
_lblState.pack();
}
});
} else if (state == TomcatServerStateListener.STATE_STOPPING) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
_btnStartRuntime.setEnabled(false);
_btnRestartRuntime.setEnabled(false);
_lblState.setText("stopping");
_btnStopRuntime.setEnabled(false);
_linkOpenAdminPage.setEnabled(false);
// _itemOpenInAdminClient.setEnabled(false);
// _itemOpenInBrowser.setEnabled(false);
// _itemOpenInContentManager.setEnabled(false);
_lblState.pack();
}
});
} else {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
_btnStartRuntime.setEnabled(true);
_btnRestartRuntime.setEnabled(false);
_btnStopRuntime.setEnabled(false);
_lblState.setText("stopped");
_linkOpenAdminPage.setEnabled(false);
// _itemOpenInAdminClient.setEnabled(false);
// _itemOpenInBrowser.setEnabled(false);
// _itemOpenInContentManager.setEnabled(false);
_lblState.pack();
}
});
}
}
@Override
public void dispose() {
TomcatUtils.getInstance().removeListener(this);
_model.getWgaRuntime().removeListener(this);
}
public void wgaConfigurationChanged(WGAConfiguration config) {
refreshWebApplications();
}
private void refreshWebApplications() {
if (_webAppModel != null) {
_webAppModel.refresh(retrieveWebApplications());
getManagedForm().reflow(true);
}
}
private void handleOpenInBrowser() {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
// check if runtime is started
if (!TomcatUtils.getInstance().isRunning(_model.getWgaRuntime()) || !TomcatUtils.getInstance().acceptRequests()) {
MessageDialog.openWarning(getSite().getShell(), "Warning", "The current runtime is not started.");
return;
}
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
IWebBrowser browser = WGADesignerPlugin.getDefault().createBrowser(WGADesignerPlugin.DEFAULT_BROWSER_ID);
browser.openURL(_model.getWgaRuntime().getDefaultURL(app.getContentStore()));
} catch (PartInitException e1) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to open web application", e1);
}
} else {
MessageDialog.openInformation(getSite().getShell(), "Selection required", "Please select a web application for this action first.");
}
}
private void handleOpenInDesignEditor() {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
Map<String, IContainer> connectedDesigns;
try {
connectedDesigns = _model.getWgaRuntime().getConnectedDesignContainers();
IContainer design = connectedDesigns.get(app.getContentStore().getKey());
if (design !=null && design.exists()){
WGADesignStructureHelper helper = new WGADesignStructureHelper(design);
WorkbenchUtils.openEditor(Plugin.getDefault().getWorkbench(), helper.getSyncInfo(), ExternalResourceIDs.EDITOR_WGA_DESIGN);
}
else {
MessageDialog.openWarning(getSite().getShell(), "Unable to determine design", "Unable to determine design for application '" + app.getContentStore().getKey() + "'.");
}
} catch (IncompatibleWGAConfigVersion e1) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to determine design", "Unable to determine design for application '" + app.getContentStore().getKey() + "'. WGA configuration is incompatible.", e1);
} catch (IOException e1) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to determine design", "Unable to determine design for application '" + app.getContentStore().getKey() + "'. Cannot read WGA configuration.", e1);
}
} catch (Exception e1) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to open Design Editor", e1);
}
} else {
MessageDialog.openInformation(getSite().getShell(), "Selection required", "Please select a web application for this action first.");
}
}
private void handleOpenInContentManager() {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
IWebBrowser browser = WGADesignerPlugin.getDefault().createBrowser(OpenContentManager.BROWSER_ID);
browser.openURL(_model.getWgaRuntime().getContentManagerURL(app.getContentStore()));
} catch (PartInitException e1) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to open Content Manager", e1);
}
} else {
MessageDialog.openInformation(getSite().getShell(), "Selection required", "Please select a web application for this action first.");
}
}
private void handleOpenInAdminClient() {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
IWebBrowser browser = WGADesignerPlugin.getDefault().createBrowser(OpenContentManager.BROWSER_ID);
browser.openURL(_model.getWgaRuntime().getAdminClientURL(app.getContentStore()));
} catch (PartInitException e1) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to open Admin Client", e1);
}
} else {
MessageDialog.openInformation(getSite().getShell(), "Selection required", "Please select a web application for this action first.");
}
}
private void handleExportWebApplication() {
if (_tblWebApplications.getTable().getSelectionCount() > 0) {
try {
WebApplication app = _webAppModel.getBeans().get(_tblWebApplications.getTable().getSelectionIndex());
IStructuredSelection selection = new SingleStructuredSelection(app);
WorkbenchUtils.openWizard(WGADesignerPlugin.getDefault().getWorkbench(), ResourceIDs.WIZARD_EXPORT_WGAAPPLICATION, selection);
} catch (Exception e) {
WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getSite().getShell(), "Unable to open export wizard for web application", e);
}
} else {
MessageDialog.openInformation(getSite().getShell(), "Selection required", "Please select a web application for this action first.");
}
}
}