use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project jbosstools-hibernate by jbosstools.
the class HibernatePropertiesComposite method createSetupAction.
private Runnable createSetupAction() {
return new Runnable() {
@Override
public void run() {
IPath initialPath = getConfigurationFilePath();
int defaultChoice = 0;
if (initialPath != null) {
defaultChoice = 1;
}
MessageDialog dialog = createSetupDialog(HibernateConsoleMessages.ConsoleConfigurationMainTab_setup_configuration_file, HibernateConsoleMessages.ConsoleConfigurationMainTab_do_you_want_to_create_new_cfgxml, defaultChoice);
int answer = dialog.open();
IPath cfgFile = null;
if (answer == 0) {
// create new
cfgFile = handleConfigurationFileCreate();
} else if (answer == 1) {
// use existing
cfgFile = handleConfigurationFileBrowse();
}
if (cfgFile != null) {
HibernatePropertiesComposite.this.cfgFile.setText(makeClassPathRelative(cfgFile).toString());
}
}
protected IPath makeClassPathRelative(IPath cfgFile) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource res = root.findMember(cfgFile);
if (res != null && res.exists() && res.getType() == IResource.FILE) {
IPackageFragmentRoot[] allPackageFragmentRoots = getSourcePackageFragmentRoots();
for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) {
if (iPackageFragmentRoot.getResource().getFullPath().isPrefixOf(cfgFile)) {
cfgFile = cfgFile.removeFirstSegments(iPackageFragmentRoot.getResource().getFullPath().segmentCount());
return cfgFile;
}
}
}
return res.getLocation();
}
private MessageDialog createSetupDialog(String title, String question, int defaultChoice) {
return new MessageDialog(getShell(), title, null, question, MessageDialog.QUESTION, new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_create_new, HibernateConsoleMessages.ConsoleConfigurationMainTab_use_existing, IDialogConstants.CANCEL_LABEL }, defaultChoice);
}
private IPath handleConfigurationFileBrowse() {
IPath[] paths = chooseFileEntries();
if (paths != null && paths.length == 1) {
return paths[0];
}
return null;
}
public IPath[] chooseFileEntries() {
TypedElementSelectionValidator validator = new TypedElementSelectionValidator(new Class[] { IFile.class }, false);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource focus = getConfigurationFilePath() != null ? root.findMember(getConfigurationFilePath()) : null;
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider() {
public Object[] getElements(Object element) {
IPackageFragmentRoot[] sourcePackageFragmentRoots = getSourcePackageFragmentRoots();
IResource[] ress = new IResource[sourcePackageFragmentRoots.length];
for (int i = 0; i < sourcePackageFragmentRoots.length; i++) {
ress[i] = sourcePackageFragmentRoots[i].getResource();
}
return ress;
}
});
dialog.setValidator(validator);
dialog.setAllowMultiple(false);
dialog.setTitle(HibernateConsoleMessages.ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file);
dialog.setMessage(HibernateConsoleMessages.ConsoleConfigurationMainTab_choose_file_to_use_as_hibernate_cfg_xml);
dialog.addFilter(new FileFilter(new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_cfg_xml }, null, true, false));
dialog.setInput(root);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setInitialSelection(focus);
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
IPath[] res = new IPath[elements.length];
for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i];
res[i] = elem.getFullPath();
}
return res;
}
return null;
}
private IPath handleConfigurationFileCreate() {
NewConfigurationWizard wizard = new NewConfigurationWizard();
wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
wdialog.create();
IWizardPage configPage = wizard.getPage(HibernateConsoleMessages.ConsoleConfigurationMainTab_wizard_page);
if (configPage != null && configPage instanceof NewConfigurationWizardPage) {
((NewConfigurationWizardPage) configPage).setCreateConsoleConfigurationVisible(false);
}
// This opens a dialog
if (wdialog.open() == Window.OK) {
WizardNewFileCreationPage createdFilePath = ((WizardNewFileCreationPage) wizard.getStartingPage());
if (createdFilePath != null) {
// createNewFile() does not creates new file if it was created by wizard (OK was pressed)
return createdFilePath.createNewFile().getFullPath();
}
}
return null;
}
};
}
use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project webtools.sourceediting by eclipse.
the class ExportXMLCatalogWizard method addPages.
public void addPages() {
exportPage = new WizardNewFileCreationPage("XML Catalog Export", getSelection());
exportPage.setTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE);
exportPage.setDescription(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION);
// $NON-NLS-1$
exportPage.setFileExtension("xml");
addPage(exportPage);
}
use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project bndtools by bndtools.
the class BlueprintXmlFileWizard method addPages.
@Override
public void addPages() {
mainPage = new WizardNewFileCreationPage("newFilePage", selection) {
@Override
protected InputStream getInitialContents() {
return getTemplateContents();
}
};
mainPage.setTitle("New Blueprint XML Descriptor");
// $NON-NLS-1$
mainPage.setFileExtension("xml");
mainPage.setAllowExistingResources(false);
setupMainPageLocation();
bndFileSelector = new WizardBndFileSelector();
addPage(mainPage);
addPage(bndFileSelector);
}
use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project linuxtools by eclipse.
the class NewSuppressionWizard method addPages.
/**
* Adding the page to the wizard.
*/
@Override
public void addPages() {
// $NON-NLS-1$
page = new WizardNewFileCreationPage("newSuppressionPage", selection);
// $NON-NLS-1$
page.setTitle(Messages.getString("NewSuppressionWizard.NewWizard_title"));
// $NON-NLS-1$
page.setDescription(Messages.getString("NewSuppressionWizard.NewWizard_description"));
// $NON-NLS-1$
page.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(ValgrindEditorPlugin.PLUGIN_ID, "icons/newsupp_wiz.png"));
page.setFileExtension(EXT_SUPP);
addPage(page);
}
use of org.eclipse.ui.dialogs.WizardNewFileCreationPage in project abstools by abstools.
the class NewABSFileWizard method addPages.
@Override
public void addPages() {
IStructuredSelection projectSelectionFromModulePath = getProjectSelectionFromModulePath(selection);
mainPage = new WizardNewFileCreationPage(WIZARD_TITLE, projectSelectionFromModulePath);
mainPage.setTitle(WIZARD_TITLE);
mainPage.setFileExtension(ABS_FILE_EXTENSION);
mainPage.setDescription(WIZARD_DESCRIPTION);
addPage(mainPage);
}
Aggregations