下面列出了怎么用org.eclipse.swt.widgets.Shell的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates a new instance
* @param parent
* @param config
*/
public DialogClassificationConfiguration(Shell parent,
ARXClassificationConfiguration<?> config) {
this.dialog = new PreferencesDialog(parent,
Resources.getMessage("DialogClassificationConfiguration.0"), //$NON-NLS-1$
Resources.getMessage("DialogClassificationConfiguration.1")); //$NON-NLS-1$
this.config = config;
if (config instanceof ClassificationConfigurationLogisticRegression) {
createContentForLogisticRegression((ClassificationConfigurationLogisticRegression) config);
} else if (config instanceof ClassificationConfigurationNaiveBayes) {
createContentForNaiveBayes((ClassificationConfigurationNaiveBayes) config);
} else if (config instanceof ClassificationConfigurationRandomForest) {
createContentForRandomForest((ClassificationConfigurationRandomForest) config);
} else {
throw new IllegalArgumentException("Unknown classification configuration");
}
}
/**
* Create the dialog.
* @param parent
* @param style
*/
public RestoreDatabaseDialog(Shell parent) {
super(parent, SWT.DIALOG_TRIM | SWT.RESIZE);
setText("Create and Restore Database");
newDatabaseDialog = new DirectoryDialog(parent);
newDatabaseDialog.setText("Create Database");
newDatabaseDialog.setMessage("Select a folder to hold a new database.");
newDatabaseDialog.setFilterPath(System.getProperty("user.home"));
restoreFileDialog = new FileDialog(Core.getShell(), SWT.OPEN);
restoreFileDialog.setFilterPath(System.getProperty("user.home"));
restoreFileDialog.setFilterExtensions(new String[] {"*.rel", "*.*"});
restoreFileDialog.setFilterNames(new String[] {"Rel script", "All Files"});
restoreFileDialog.setText("Load Backup");
}
private int showQueryDialog(final String message, final String[] buttonLabels, int[] returnCodes) {
final Shell shell= getShell();
if (shell == null) {
JavaPlugin.logErrorMessage("AddGetterSetterAction.showQueryDialog: No active shell found"); //$NON-NLS-1$
return IRequestQuery.CANCEL;
}
final int[] result= { Window.CANCEL};
shell.getDisplay().syncExec(new Runnable() {
public void run() {
String title= ActionMessages.AddGetterSetterAction_QueryDialog_title;
MessageDialog dialog= new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 0);
result[0]= dialog.open();
}
});
int returnVal= result[0];
return returnVal < 0 ? IRequestQuery.CANCEL : returnCodes[returnVal];
}
void installListeners() {
// Listeners on this popup's table and scroll bar
proposalTable.addListener(SWT.FocusOut, this);
final ScrollBar scrollbar = proposalTable.getVerticalBar();
if (scrollbar != null) {
scrollbar.addListener(SWT.Selection, this);
}
// Listeners on this popup's shell
getShell().addListener(SWT.Deactivate, this);
getShell().addListener(SWT.Close, this);
// Listeners on the target control
control.addListener(SWT.MouseDoubleClick, this);
control.addListener(SWT.MouseDown, this);
control.addListener(SWT.Dispose, this);
control.addListener(SWT.FocusOut, this);
// Listeners on the target control's shell
final Shell controlShell = control.getShell();
controlShell.addListener(SWT.Move, this);
controlShell.addListener(SWT.Resize, this);
}
@Override
public IInformationControl createInformationControl(Shell parent) {
// try { -- this would show the 'F2' for focus, but we don't actually handle that, so, don't use it.
// tooltipAffordanceString = EditorsUI.getTooltipAffordanceString();
// } catch (Throwable e) {
// //Not available on Eclipse 3.2
// }
//Note: don't use the parent because when it's closed we don't want the parent to have focus (we want the original
//widget that had focus to regain the focus).
// if (parent == null) {
// parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// }
String tooltipAffordanceString = null;
if (this.informationPresenterControlManager != null) {
InformationPresenterControlManager m = this.informationPresenterControlManager.get();
if (m != null) {
tooltipAffordanceString = m.getTooltipAffordanceString();
}
}
PyInformationControl tooltip = new PyInformationControl(null, tooltipAffordanceString, presenter);
return tooltip;
}
/**
* @param args
*/
public static void main(final String[] args) {
final Display display = new Display();
shell = new Shell(display);
shell.setText("LED Snippet");
shell.setLayout(new GridLayout(1, true));
shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
createTopPart();
createBottomPart();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
/**
* Shows the UI to choose new classpath container classpath entries. See {@link IClasspathEntry#CPE_CONTAINER} for
* details about container classpath entries.
* The query returns the selected classpath entries or an empty array if the query has
* been cancelled.
*
* @param shell The parent shell for the dialog, can be <code>null</code>
* @return Returns the selected classpath container entries or an empty array if the query has
* been cancelled by the user.
*/
public static IAddLibrariesQuery getDefaultLibrariesQuery(final Shell shell) {
return new IAddLibrariesQuery() {
public IClasspathEntry[] doQuery(final IJavaProject project, final IClasspathEntry[] entries) {
final IClasspathEntry[][] selected= {null};
Display.getDefault().syncExec(new Runnable() {
public void run() {
Shell sh= shell != null ? shell : JavaPlugin.getActiveWorkbenchShell();
selected[0]= BuildPathDialogAccess.chooseContainerEntries(sh, project, entries);
}
});
if(selected[0] == null)
return new IClasspathEntry[0];
return selected[0];
}
};
}
public ElexisEnvironmentLoginDialog(Shell shell, String openidClientSecret, String keycloakUrl,
String realmPublicKey){
super(shell);
logger = LoggerFactory.getLogger(getClass());
oauthService = new ServiceBuilder(ElexisEnvironmentLoginContributor.OAUTH2_CLIENT_ID)
.apiSecret(openidClientSecret).defaultScope("openid").callback(CALLBACK_URL)
.build(KeycloakApi.instance(keycloakUrl, ElexisEnvironmentLoginContributor.REALM_ID));
KeyFactory kf;
try {
kf = KeyFactory.getInstance("RSA");
X509EncodedKeySpec keySpecX509 =
new X509EncodedKeySpec(Base64.getDecoder().decode(realmPublicKey));
RSAPublicKey publicKey = (RSAPublicKey) kf.generatePublic(keySpecX509);
jwtParser = Jwts.parserBuilder().setSigningKey(publicKey).build();
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
logger.error("Initialization error", e);
}
}
public HyperlinkBuilder( Shell parentShell, boolean isIDE,
boolean isRelativeToProjectRoot )
{
super( parentShell, TITLE );
this.isIDE = isIDE;
this.isRelativeToProjectRoot = isRelativeToProjectRoot;
// *********** try using a helper provider ****************
IProjectFileServiceHelperProvider helperProvider = (IProjectFileServiceHelperProvider) ElementAdapterManager.getAdapter( this,
IProjectFileServiceHelperProvider.class );
if ( helperProvider != null )
{
projectFileServiceHelper = helperProvider.createHelper( );
}
else
{
projectFileServiceHelper = new DefaultProjectFileServiceHelper( );
}
}
public static Shell getActivePartShell() {
IWorkbenchPage activePage = WorkbenchUtils.getActivePage();
if (activePage == null) {
return null;
}
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart == null) {
return null;
}
IWorkbenchPartSite site = activePart.getSite();
if (site == null) {
return null;
}
return site.getShell();
}
public JobEntryDeleteFilesDialog( Shell parent, JobEntryInterface jobEntryInt, Repository rep, JobMeta jobMeta ) {
super( parent, jobEntryInt, rep, jobMeta );
jobEntry = (JobEntryDeleteFiles) jobEntryInt;
if ( this.jobEntry.getName() == null ) {
this.jobEntry.setName( BaseMessages.getString( PKG, "JobDeleteFiles.Name.Default" ) );
}
}
public InputParameterDialog( Shell parentShell, List params, Map paramValues )
{
super( parentShell,
Messages.getString( "InputParameterDialog.msg.title" ) ); //$NON-NLS-1$
this.params = params;
if ( paramValues != null )
{
this.paramValues.putAll( paramValues );
}
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
// Register help listener on the shell
newShell.addHelpListener(new HelpListener() {
public void helpRequested(HelpEvent event) {
// call perform help on the current page
if (currentPage != null) {
currentPage.performHelp();
}
}
});
}
private Display getDisplay() {
Shell shell = getShell();
if (shell != null) {
return shell.getDisplay();
}
return null;
}
public TwoChoiceDialog(Shell parentShell, String dialogTitle,
Image dialogTitleImage, String dialogMessage,
int dialogImageType, String[] dialogButtonLabels,
int defaultIndex) {
super(parentShell, dialogTitle, dialogTitleImage, dialogMessage,
dialogImageType, dialogButtonLabels, defaultIndex);
int style = SWT.NONE;
style &= SWT.SHEET;
setShellStyle(getShellStyle() | style);
}
public AddResourcesToClientBundleDialog(Shell parent, IProject project,
IType clientBundleType, IFile[] files) {
super(parent);
this.project = project;
this.clientBundleType = clientBundleType;
this.files = files;
this.bundledResourcesBlock = new BundledResourcesSelectionBlock(
"Bundled resources:", fieldAdapter);
setTitle("Add Resources to ClientBundle");
setHelpAvailable(false);
setShellStyle(getShellStyle() | SWT.RESIZE);
}
public void startDerbyServer( IProject proj) throws CoreException {
String args = CommonNames.START_DERBY_SERVER;
String vmargs="";
DerbyProperties dprop=new DerbyProperties(proj);
//Starts the server as a Java app
args+=" -h "+dprop.getHost()+ " -p "+dprop.getPort();
//Set Derby System Home from the Derby Properties
if((dprop.getSystemHome()!=null)&& !(dprop.getSystemHome().equals(""))){
vmargs=CommonNames.D_SYSTEM_HOME+dprop.getSystemHome();
}
String procName="["+proj.getName()+"] - "+CommonNames.DERBY_SERVER+" "+CommonNames.START_DERBY_SERVER+" ("+dprop.getHost()+ ", "+dprop.getPort()+")";
ILaunch launch = DerbyUtils.launch(proj, procName ,
CommonNames.DERBY_SERVER_CLASS, args, vmargs, CommonNames.START_DERBY_SERVER);
IProcess ip=launch.getProcesses()[0];
//set a name to be seen in the Console list
ip.setAttribute(IProcess.ATTR_PROCESS_LABEL,procName);
// saves the mapping between (server) process and project
//servers.put(launch.getProcesses()[0], proj);
servers.put(ip, proj);
// register a listener to listen, when this process is finished
DebugPlugin.getDefault().addDebugEventListener(listener);
//Add resource listener
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.addResourceChangeListener(rlistener);
setRunning(proj, Boolean.TRUE);
Shell shell = new Shell();
MessageDialog.openInformation(
shell,
CommonNames.PLUGIN_NAME,
Messages.D_NS_ATTEMPT_STARTED+dprop.getPort()+".");
}
public ActionPGPDecryptFilesDialog( Shell parent, IAction action,
WorkflowMeta workflowMeta ) {
super( parent, action, workflowMeta );
this.action = (ActionPGPDecryptFiles) action;
if ( this.action.getName() == null ) {
this.action.setName( BaseMessages.getString( PKG, "ActionPGPDecryptFiles.Name.Default" ) );
}
}
public OptionSettingDialog(Shell parentShell, DiagramSettings settings, ERDiagram diagram) {
super(parentShell);
this.diagram = diagram;
this.settings = settings;
this.tabWrapperList = new ArrayList<>();
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
if(title == null){
newShell.setText(Messages.selectMissingJarTitle) ;
}else{
newShell.setText(title) ;
}
}
public static void main(String[] args) {
Display display = new Display();
shell = new Shell(display);
positiongLabel = new Label(shell, SWT.BORDER);
int x= 60;
int y=20;
int width =400;
int height=200;
positiongLabel.setBounds(x, y, width, height);
int toolbarSize = 30;
shell.setBounds(200, 400, width+2*x , height + 2*y +toolbarSize);
shell.open();
shell.addMouseMoveListener(e -> showSize(e));
positiongLabel.addMouseMoveListener(e -> showSize(e));
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private HostPagePathSelectionDialog(Shell parent, IProject project) {
super(parent, new HostPagePathLabelProvider(),
new HostPagePathContentProvider());
setTitle("Existing Folder Selection");
setMessage("Choose a location for the HTML page");
rootTreeItems = HostPagePathTreeItem.createRootItems(project);
setInput(rootTreeItems);
setComparator(new ViewerComparator());
}
/**
*
*
* @param parent
* @param controller
* @param file
* @param data
*/
public DialogOpenHierarchy(final Shell parent,
final Controller controller,
final String file,
boolean data) {
super(parent);
this.file = file;
this.data = data;
}
public StepPerformanceSnapShotDialog( Shell parent, String title,
Map<String, List<StepPerformanceSnapShot>> stepPerformanceSnapShots, long timeDifference ) {
super( parent );
this.parent = parent;
this.display = parent.getDisplay();
this.props = PropsUI.getInstance();
this.timeDifference = timeDifference;
this.title = title;
this.stepPerformanceSnapShots = stepPerformanceSnapShots;
Set<String> stepsSet = stepPerformanceSnapShots.keySet();
steps = stepsSet.toArray( new String[stepsSet.size()] );
Arrays.sort( steps );
}
public ActionSuccessDialog( Shell parent, IAction action, WorkflowMeta workflowMeta ) {
super( parent, action, workflowMeta );
this.action = (ActionSuccess) action;
if ( this.action.getName() == null ) {
this.action.setName( BaseMessages.getString( PKG, "ActionSuccessDialog.Name.Default" ) );
}
}
@Override
public void performHelp() {
Shell shell = new Shell(getShell());
shell.setText("Saros XMPP Accounts");
shell.setLayout(new GridLayout());
shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Browser browser = new Browser(shell, SWT.NONE);
browser.setUrl("https://www.saros-project.org/documentation/setup-xmpp.html");
browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
shell.open();
}
/**
* Shows an error dialog that gives information on the given {@link Throwable}.
*
* This static method may be invoked at any point during startup as it does not rely on activators to be loaded.
*/
public static void showError(Throwable t) {
int dialogW = 400;
int dialogH = 300;
Display display = new Display();
Shell shell = new Shell(display);
Rectangle bounds = display.getPrimaryMonitor().getBounds();
shell.setLocation(bounds.width / 2 - dialogW / 2, bounds.height / 2 - dialogH / 2);
shell.setText("Fatal Error with Dependency Injection.");
shell.setSize(dialogW, dialogH);
shell.setLayout(new FillLayout());
Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
String sStackTrace = sw.toString();
text.setText(sStackTrace);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public PipelineDialog( Shell parent, int style, PipelineMeta pipelineMeta ) {
super( parent, style );
this.props = PropsUi.getInstance();
this.pipelineMeta = pipelineMeta;
changed = false;
}
/**
* DumbMessageDialog constructor
*
* @param parent the parent shell
*/
public DumbMessageDialog(Shell parent) {
super(parent);
// Create the image
try {
image = new Image(parent.getDisplay(), new FileInputStream(CoreImages.LOGO_DIALOG));
} catch (FileNotFoundException e) {}
// Set the default message
message = "Are you sure you want to do something that dumb?";
}
/**
* Static method that opens a new dialog or switches the existing dialog to
* another account id. The dialog shows back and forward buttons to navigate
* between accounts inspected.
*
* @param accountId
* @return
*/
public static void show(final Long accountId, final INxtService nxt,
final IStylingEngine engine, final IUserService userService,
final UISynchronize sync, final IContactsService contactsService) {
sync.syncExec(new Runnable() {
@Override
public void run() {
Shell shell = Display.getCurrent().getActiveShell();
if (shell != null) {
while (shell.getParent() != null) {
shell = shell.getParent().getShell();
}
}
if (INSTANCE == null) {
INSTANCE = new InspectAccountDialog(shell, accountId, nxt, engine,
userService, sync, contactsService);
INSTANCE.history.add(accountId);
INSTANCE.historyCursor = 0;
INSTANCE.open();
}
else {
INSTANCE.history.add(accountId);
INSTANCE.historyCursor = INSTANCE.history.size() - 1;
INSTANCE.setAccountId(accountId);
INSTANCE.getShell().forceActive();
}
}
});
}