Opening a new window in MAUI - maui

In WPF the below code opens a new window.
Window abc = new Window();
abc.Show();
But for MAUI window, I cant find the show option. How to open a window in MAUI?

var secondWindow = new Window {
Page = new MySecondPage {
// ...
}
};
Application.Current.OpenWindow(secondWindow);
https://devblogs.microsoft.com/dotnet/announcing-dotnet-maui-preview-11/

Try;
Navigation.PushAsync(new MainPage());

Try this,
await Shell.Current.GoToAsync("///MainPage");

Related

How to close the current tab of the browser in protractor with out closing the complete browser

In the application i have two options "Google , Twitter" . When i click on any option it will open in new tab.
In my test case , i would like to click on google or twitter option and close the google or twitter tab and return back to the my application.
Is there any way to close only newly opened tab.
I tried below solutions.
browser.close(); is closing the entire browser.
Can any one help me how to close only tab of the browser ( in my case google tab or twitter tab) with out closing the entire browser in protractor
You can try the following:
Switch to the new opened tab. Close the current windows (in this case, the new tab). Switch back to the first window.
browser.getAllWindowHandles().then((handles) => {
browser.driver.switchTo().window(handles[1]);
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});
This is how I used it in one project.
const allWindowHandlers = await browser.getAllWindowHandles();
if (allWindowHandlers.length > 1) {
for (let windowHandlerIndex = 1; windowHandlerIndex < allWindowHandlers.length; windowHandlerIndex++) {
const windowHandler = allWindowHandlers[windowHandlerIndex];
await browser.switchTo().window(windowHandler);
await browser.close();
}
}
await browser.switchTo().window(allWindowHandlers[0]);
You can use it inside your steps implementation.
You can use it before starting a new scenario, to be sure that only the first window is selected and everything else is closed.
I did and this and it works for me :
browser.getAllWindowHandles().then(function(handles) {
let newWindowHandle = handles[1]; // this is your new window
browser.switchTo().window(newWindowHandle).then(function() {
browser.close();
browser.switchTo().window(handles[0]);
});
});

How to open a filedialog within an Eclipse Wizard

I'm writing an Eclipseplugin, which has to create a new project. This works so far, but i need to copy an external file into the projectfolder. I intend to have a 'Browse' button on one of my WizardPages, which opens a filedialog, where the user can browse to the file and after closing the dialog i can use the path to this file for various actions. My problem is that the dialog window never opens. Right now i'm trying it that way (snippet from my wizardpage):
public void createControl(Composite composite) {
this.container = new Composite(composite, SWT.NONE);
GridLayout layout = new GridLayout();
this.container.setLayout(layout);
layout.numColumns = 2;
Button browseButton = new Button(this.container, SWT.PUSH);
browseButton.setText("Browse");
browseButton.addSelectionListener(new SelectionListener() {
#Override
public void widgetDefaultSelected(SelectionEvent arg0) {
FileDialog fileDialog = new FileDialog(DataPage.this.container.getShell(), SWT.OPEN);
fileDialog.setText("JZOS created File");
String path = fileDialog.open();
DataPage.this.setJzosCreatedName(path);
}
});
I tried several implementations, that i have seen in examples and tutorials but nothing did work. I'm assuming a problem with the Shell that i give to the filedialog. I tried to open a new Shell within the widgetDefaultSelected function but it didn't work either. Any Suggestions?
You should be using the widgetSelected method of SelectionListener not widgetDefaultSelected

Check whether an Eclipse view is visible

I created a plug-in action which shows a view & hides a view. Here is my code:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.showView("com.sample.views.Example");
page.hideView(page.findView("com.sample.views.Example"));
But how can I check whether this view is in present foreground or if it is closed?
IWorkbenchPage.findView will return null if the view is not open.
IWorkbenchPage.getActivePart() returns the active part (this might be an editor or a view).
You can also use IWorkbenchPage.addPartListener to listen for changes to the parts.
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editors = page.getEditorReferences();
// How many editor open..
// System.out.println("Len : "+editors.length);
if(editors.length==0){
System.out.println("View is not visible");
}
else{
System.out.println("View is visible");
System.out.println("View or Editor Name is :: "+page.getActiveEditor().getTitle());
}
Current working view or window name display
IPartService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService();
MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(
event).getShell(), "Current Workbench Window", service.getActivePart().getTitle()+"");

Open new Tab when button is clicked

using wicket I want to open a new tab when a button or link is clicked, how can I achieve it?
what I have managed to do is to open it in a pop up like this:
PopupSettings popupSettings = new PopupSettings("popuppagemap").setLeft(0).setHeight(500).setWidth(500).setHeight(0);
// Popup example
final Link<Void> setPopupSettings = new BookmarkablePageLink<Void>("searchBtn", HomePage.class)
.setPopupSettings(popupSettings);
but this opens it in a new window.
no problem to open a link in a new tab: just add 'target="_blank"' to the link.
final Link<Void> link = new BookmarkablePageLink<Void>("link", HomePage.class){
#Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
tag.put("target", "_blank");
}
};
add(link);
If you want a button instead of a link that opens a new tab you can use:
html:
<a wicket:id="tabFormViewEmpBut"><button type="button">Click Me!</button></a>
And
Java wicket:
final Link<Void> link = new BookmarkablePageLink<Void>("tabFormViewEmpBut", HomePage.class) {
#Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
tag.put("target", "_blank");
}
};
add(link);
This is not a function of Wicket but of your browser and HTML in general.
simply add a target tag to your link:
My Cool Link
What actually happens when the link is clicked will depend on the browser. Before browsers had tabs, this would have opened a new window, now most browsers will open a new tab by default, however, you can't depend on that happening because the feature is optional.

Close editor if button inside this editor is pressed?? (RCP eclipse)

favorite
I have a UI in which when I select an item (in a tree) and then press a button "add", I get a new editor. With each item I can get an editor. (but all have the same ID)
My purpose is to close only the editor of item1, for example, when I press "save". I'm able to close all the editors with: getSite().getWorkbenchWindow().getActivePage().closeAllEditors(true);
But not only the one that I need to close. The following solution helped me:
// Creating and opening
MyObject item1 = ... //create item1
// open editor
myInput = new MyEditorInput(item1)
IDE.openEditor(workbenchPage, myInput, MY_EDITOR_ID);
// Closing
tmpInput = new MyEditorInput(item1)
IEditorReference[] editorReferences = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getEditorReferences();
List<IEditorReference> relevantEditors = new ArrayList<IEditorReference>();
for (IEditorReference iEditorReference : editorReferences) {
if (iEditorReference.getEditorInput().equals(tmpInput)) {
relevantEditors.add(iEditorReference);
}
}
PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.closeEditors(
(IEditorReference[]) relevantEditors.toArray(new IEditorReference[relevantEditors
.size()]), true);
….but I still have some problems... As I can open many editors in the same time, and all of them have the same button "save", it happens that I press "save" in editor1 but close editor3... Actually, I save the last editor to be open (thanks to its "item")... this is the problem.. So I'm wondering if there is a way to identify the editor in which the button exists, so that I close it..
Thanks a lot I appreciate any help or hint (Sorry if my questions look easy and not worth being asked, but I'm still a beginner...)
if the Button is rendered in your IEditorPart implementation, you can close the editor directly in your EditorPart.
button.addListener(SWT.Selection, new Listener() {
#Override
public void handleEvent(Event event) {
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().closeEditor(this, true);
}
});
Selected editor open or another editor can be close using RCP eclipse.
Multiple Editor open at time selected editor can be open or close using RCP eclipse.
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
EmployeeEditorInput input = new EmployeeEditorInput();
//List out all the editors open
IEditorReference[] editors = page.getEditorReferences();
for (int i=0; i<editors.length; i++) {
//class : EmployeeEditor
//public static final String Id="rcp_demo.Editor.emp";
if (editors[i].getId().equals(EmployeeEditor.Id)) {
page.activate(editors[i].getEditor(true));
//or
//page.closeEditor(page.getActiveEditor(),true);
System.out.println("Employee Editor Exist");
return null;
}
else
{
page.closeEditor(page.getActiveEditor(), true);
System.out.println("Close other Editor");
}
}