| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.uruma.rcp.ui; |
| 17 | |
|
| 18 | |
import java.util.ResourceBundle; |
| 19 | |
|
| 20 | |
import org.eclipse.swt.widgets.Display; |
| 21 | |
import org.eclipse.swt.widgets.Shell; |
| 22 | |
import org.eclipse.ui.application.IWorkbenchConfigurer; |
| 23 | |
import org.eclipse.ui.application.IWorkbenchWindowConfigurer; |
| 24 | |
import org.eclipse.ui.application.WorkbenchAdvisor; |
| 25 | |
import org.eclipse.ui.application.WorkbenchWindowAdvisor; |
| 26 | |
import org.seasar.eclipse.common.util.ImageManager; |
| 27 | |
import org.seasar.framework.util.StringUtil; |
| 28 | |
import org.seasar.uruma.component.rcp.WorkbenchComponent; |
| 29 | |
import org.seasar.uruma.core.UrumaConstants; |
| 30 | |
import org.seasar.uruma.core.UrumaMessageCodes; |
| 31 | |
import org.seasar.uruma.exception.NotFoundException; |
| 32 | |
import org.seasar.uruma.log.UrumaLogger; |
| 33 | |
import org.seasar.uruma.rcp.UrumaService; |
| 34 | |
import org.seasar.uruma.rcp.util.UrumaServiceUtil; |
| 35 | |
import org.seasar.uruma.ui.dialogs.UrumaErrorDialog; |
| 36 | |
import org.seasar.uruma.util.MessageUtil; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | public class UrumaWorkbenchAdvisor extends WorkbenchAdvisor implements |
| 44 | |
UrumaMessageCodes, UrumaConstants { |
| 45 | 0 | private static final UrumaLogger logger = UrumaLogger |
| 46 | |
.getLogger(UrumaWorkbenchAdvisor.class); |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
@Override |
| 52 | |
public void initialize(final IWorkbenchConfigurer configurer) { |
| 53 | 0 | UrumaService service = UrumaServiceUtil.getService(); |
| 54 | |
|
| 55 | 0 | service.getContainer().register(configurer); |
| 56 | |
|
| 57 | |
|
| 58 | 0 | WorkbenchComponent workbench = service.getWorkbenchComponent(); |
| 59 | 0 | boolean flg = Boolean.parseBoolean(workbench.saveAndRestore); |
| 60 | 0 | configurer.setSaveAndRestore(flg); |
| 61 | |
|
| 62 | 0 | ResourceBundle imageBundle = service.getImageBundle(); |
| 63 | 0 | if (imageBundle != null) { |
| 64 | 0 | logger.log(UrumaMessageCodes.LOADING_IMAGE_BUNDLE, imageBundle); |
| 65 | 0 | ImageManager.loadImages(imageBundle); |
| 66 | |
} |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
@Override |
| 73 | |
public boolean preShutdown() { |
| 74 | 0 | ImageManager.dispose(); |
| 75 | 0 | return true; |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
@Override |
| 82 | |
public String getInitialWindowPerspectiveId() { |
| 83 | 0 | UrumaService service = UrumaServiceUtil.getService(); |
| 84 | |
|
| 85 | 0 | String perspectiveId = service.getWorkbenchComponent().initialPerspectiveId; |
| 86 | |
|
| 87 | 0 | if (StringUtil.isNotBlank(perspectiveId)) { |
| 88 | 0 | WorkbenchComponent workbench = UrumaServiceUtil.getService() |
| 89 | |
.getWorkbenchComponent(); |
| 90 | 0 | if (workbench.findPerspective(perspectiveId) != null) { |
| 91 | 0 | return service.createRcpId(perspectiveId); |
| 92 | |
} else { |
| 93 | 0 | throw new NotFoundException( |
| 94 | |
UrumaMessageCodes.PERSPECTIVE_NOT_FOUND, perspectiveId); |
| 95 | |
} |
| 96 | |
} else { |
| 97 | 0 | return service.createRcpId(UrumaConstants.DEFAULT_PERSPECTIVE_ID); |
| 98 | |
} |
| 99 | |
} |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( |
| 106 | |
final IWorkbenchWindowConfigurer configurer) { |
| 107 | 0 | return new UrumaWorkbenchWindowAdvisor(configurer); |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
@Override |
| 114 | |
public void eventLoopException(final Throwable throwable) { |
| 115 | 0 | logger.log(EXCEPTION_OCCURED_WITH_REASON, throwable, throwable |
| 116 | |
.getMessage()); |
| 117 | |
|
| 118 | 0 | Display display = getWorkbenchConfigurer().getWorkbench().getDisplay(); |
| 119 | 0 | boolean displayCreated = false; |
| 120 | 0 | if (display == null) { |
| 121 | 0 | display = Display.getCurrent(); |
| 122 | |
|
| 123 | 0 | if (display == null) { |
| 124 | 0 | display = new Display(); |
| 125 | 0 | displayCreated = true; |
| 126 | |
} |
| 127 | |
} |
| 128 | 0 | Shell shell = new Shell(display); |
| 129 | 0 | String msg = MessageUtil.getMessageWithBundleName(URUMA_MESSAGE_BASE, |
| 130 | |
"RCP_EXCEPTION_OCCURED"); |
| 131 | 0 | UrumaErrorDialog dialog = new UrumaErrorDialog(shell, "Uruma", msg, |
| 132 | |
throwable); |
| 133 | 0 | dialog.open(); |
| 134 | 0 | shell.dispose(); |
| 135 | |
|
| 136 | 0 | if (displayCreated) { |
| 137 | 0 | display.dispose(); |
| 138 | |
} |
| 139 | 0 | } |
| 140 | |
} |