blob: 8b7386cd7474f916db7636930dcd8983f0246998 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*******************************************************************************
* Copyright (c) 2010 Tasktop Technologies and others.
* 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:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.commons.repositories.ui;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.commons.ui.dialogs.ValidatableWizardDialog;
import org.eclipse.mylyn.internal.commons.repositories.ui.Messages;
import org.eclipse.mylyn.internal.commons.repositories.ui.RepositoriesUiPlugin;
import org.eclipse.mylyn.internal.commons.repositories.ui.wizards.NewRepositoryWizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.LegacyResourceSupport;
import org.eclipse.ui.internal.util.Util;
/**
* @author Steffen Pingel
*/
public final class RepositoryUi {
/**
* The wizard dialog width.
*/
private static final int SIZING_WIZARD_WIDTH = 500;
/**
* The wizard dialog height.
*/
private static final int SIZING_WIZARD_HEIGHT = 500;
public static final String ID_VIEW_REPOSITORIES = "org.eclipse.mylyn.commons.repositories.ui.navigator.Repositories"; //$NON-NLS-1$
private RepositoryUi() {
}
public static int openNewRepositoryDialog(IWorkbenchWindow workbenchWindow, String categoryId) {
NewRepositoryWizard wizard = new NewRepositoryWizard();
wizard.setCategoryId(categoryId);
wizard.setWindowTitle(Messages.NewRepositoryHandler_New_Repository);
ISelection selection = workbenchWindow.getSelectionService().getSelection();
IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
if (selection instanceof IStructuredSelection) {
selectionToPass = (IStructuredSelection) selection;
} else {
// @issue the following is resource-specific legacy code
// Build the selection from the IFile of the editor
Class resourceClass = LegacyResourceSupport.getResourceClass();
if (resourceClass != null) {
IWorkbenchPart part = workbenchWindow.getPartService().getActivePart();
if (part instanceof IEditorPart) {
IEditorInput input = ((IEditorPart) part).getEditorInput();
Object resource = Util.getAdapter(input, resourceClass);
if (resource != null) {
selectionToPass = new StructuredSelection(resource);
}
}
}
}
wizard.init(workbenchWindow.getWorkbench(), selectionToPass);
IDialogSettings workbenchSettings = RepositoriesUiPlugin.getDefault().getDialogSettings();
IDialogSettings wizardSettings = workbenchSettings.getSection("NewWizardAction"); //$NON-NLS-1$
if (wizardSettings == null) {
wizardSettings = workbenchSettings.addNewSection("NewWizardAction"); //$NON-NLS-1$
}
wizard.setDialogSettings(wizardSettings);
wizard.setForcePreviousAndNextButtons(true);
Shell parent = workbenchWindow.getShell();
ValidatableWizardDialog dialog = new ValidatableWizardDialog(parent, wizard);
dialog.create();
dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, dialog.getShell().getSize().x), SIZING_WIZARD_HEIGHT);
//PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IWorkbenchHelpContextIds.NEW_WIZARD);
return dialog.open();
}
}
|