I have developed an application using net bean,
1) I'm making project in java API 6. I'm using "Net Beans 7.1".
2) I want to use JInternalFrame in my project
3) I made another package and made "JInternalFrame" there. And then call it in my main application window by firing action performed event on "JMenuItem".
4) It works fine but only one problem occurs that is, if i click on "JMenuItem" again and again, new "JInternalFrame" of same instance are opening, How can i stop that?
5) I want that, if I open "JInternalFrame" once and then i again click on "JMenuItem" to open the same "JInternalFrame", it Should do nothing or it shows the window which already opened and minimized
sample code:
<code>
private void empDataActionPerformed(java.awt.event.ActionEvent evt) {
Emps employees = new Emps();
desktop.add(employees);
employees.setVisible(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
employees.setBounds(230, 40, screenSize.width / 2 - 80, screenSize.height / 2 + 105);
}
<code>
please I need help.
Here is may sample code. hope this help.
Menu action to call internal frame in main application where JdesktopPane in it.
private void YourJinternalFrameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
YourJinternalFrame nw = YourJinternalFrame.getInstance();
nw.pack();
//usefull part for you.. if open shows, if not creates new one
if (nw.isVisible()) {
} else {
desktopPane.add(nw);
nw.setVisible(true);
}
try {
nw.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex);
}
}
put this inside of your YourJinternalFrame
private static YourJinternalFrame myInstance;
public static YourJinternalFrame getInstance() {
if (myInstance == null) {
myInstance = new YourJinternalFrame();
}
return myInstance;
Related
I am using GWTUpload , the library is in here https://code.google.com/p/gwtupload/
The Example code at client side found on that website has this structure:
// Attach an image to the pictures viewer
private OnLoadPreloadedImageHandler showImage = new OnLoadPreloadedImageHandler() {
public void onLoad(PreloadedImage image) {
//showImageFlowPanel code solution 1
image.setWidth("75px");
showImageFlowPanel.add(image);
}
};
private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
public void onFinish(IUploader uploader) {
if (uploader.getStatus() == Status.SUCCESS) {
new PreloadedImage(uploader.fileUrl(), showImage);
UploadedInfo info = uploader.getServerInfo();
String headShotImageUrl="http://"+Window.Location.getHost()+"/" +"images/uploaded/"+info.message;
//headShotImage code solution 2
if(!"".equals(headShotImageUrl) && UriUtils.isSafeUri(headShotImageUrl)){
headShotImage.setUrl(UriUtils.fromString(headShotImageUrl));
}
}
}
};
The example uses showImageFlowPanel (solution 1) to store the image but I want to store the image inside headShotImage which take the url after user uploaded image successfully, see the headShotImage (solution 2) code above.
Ok, the headShotImage code work fine but I dont know how to remove it when users remove the image. If I use showImageFlowPanel as in the solution 1 then the program remove the image automatically for me and I do not need to do anything.
So my question is "Where to call an Action when user removes an uploaded image in GWTUpload?"
You have to use setOnCancelUploaderHandler. Take a look to this code took from the demo.
// When the user clicks a cancel button we get an event
uploader.addOnCancelUploadHandler (
new IUploader.OnCancelUploaderHandler() {
public void onCancel(IUploader uploader) {
for (String iname : uploader.getServerMessage().getUploadedFieldNames()) {
// loadedImages is an temporary table where we are adding all uploaded files
// indexed by field name
Widget w = loadedImages.get(iname);
if (w != null) {
w.removeFromParent();
loadedImages.remove(uploader.getInputName());
}
}
}
});
i'm working on an Eclipse RCP4 project. I have different perspectives showing a set of Parts to choose informations from. After selecting what i want to see, a new Part opens and displays the objet i want to edit / view attibutes of.
I can open many parts of the same type. If i close the application, the eclipse framwork persists the position of all opened Parts. If i restart the application all previously opened Parts are open but without informations.
-How to prevent Eclipseframwork from persisting the state of Parts?
-How to close Parts on exit?
I'm searching for a way to add an "removeOnExit" tag to a Part and than close such a marked Part on exit.
Thanks in advance :)
With this you can close MParts with a specific Tag.
It seems you have to switch to the Perspective the Part is on, else it's not removed from the context wich will cause nullpointer exceptions.
#Inject
#Optional
public void doEvent(#EventTopic(EventConstants.EventTopics.CLOSE_PARTS_WITH_TAGS) String tagToClose, MApplication app,
EModelService eModelService, EPartService ePartService) {
MUIElement activePart = ePartService.getActivePart();
EPartService activePeServcie = null;
MPerspective activePerspective = null;
if (activePart instanceof MPart) {
activePeServcie = ((MPart) activePart).getContext().get(EPartService.class);
activePerspective = eModelService.getPerspectiveFor(activePart);
}
List<String> tags = new ArrayList<String>();
tags.add(tagToClose);
List<MPart> elementsWithTags = eModelService.findElements(app, null, MPart.class, tags);
for (MPart part : elementsWithTags) {
try {
logger.info("Closing part " + part.toString());
EPartService peService = part.getContext().get(EPartService.class);
peService.switchPerspective(eModelService.getPerspectiveFor(part));
peService.hidePart(part);
} catch (Exception e) {
logger.error(e);
}
}
if (activePart instanceof MPart && activePeServcie != null && activePerspective != null) {
activePeServcie.switchPerspective(activePerspective);
}
}
We too tried to migrate from Eclipse 3 to Eclipse 4.We used the comp layer and had a lot of problems with the migration. I had a similar problem with persistent store of the eclipse workbench. So parts and views had the same position as before restart.
The persistence paradigma in Eclipse 4 has changed. Please take a look here:
As far as I remember the call of configurer.setSaveAndRestore(false) does not work in Eclipse 4 correctly.
I want to achieve the functionality of selecting a working set programmatically. I tried with the below code:
IWorkingSetManager wsMgr = PlatformUI.getWorkbench().getWorkingSetManager();
IWorkingSet ws = wsMgr.getWorkingSet("custom");
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkingSet[] windowset = new IWorkingSet[]{ws};
page.setWorkingSets(windowset);
But the above code does not work and the Project Explorer does not show the working set.
Why does not the above code work and what is the solution for the above?
For updating the ProjectExplorer view with a working set, I tried the below code
IWorkingSetManager wsMgr = PlatformUI.getWorkbench().getWorkingSetManager();
IWorkingSet ws = wsMgr.getWorkingSet("custom");
ProjectExplorer pView = (ProjectExplorer)page.findView(IPageLayout.ID_PROJECT_EXPLORER);
pView.getCommonViewer().setInput(ws);
The above code displays the content of the working set in ProjectExplorer, but that is not persisted. I mean once Eclipse is restarted, instead of the working set, all projects are getting displayed.
Here's an example handler I created that can set working sets programmatically in a Project Explorer and turn on top level workingsets if it's not already on:
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow workbenchWindow = HandlerUtil
.getActiveWorkbenchWindowChecked(event);
IWorkbenchPage page = workbenchWindow.getActivePage();
IWorkingSetManager manager = workbenchWindow.getWorkbench()
.getWorkingSetManager();
ProjectExplorer projExplorer = (ProjectExplorer) page
.findView(IPageLayout.ID_PROJECT_EXPLORER);
// This is just a test, to ensure we got hold on the correct object for
// Project Explorer.
// The project explorer will get focus now.
projExplorer.setFocus();
// Obtain list of all existing working sets.
// This assumes that the debug workspace used have some working sets
// prepared.
IWorkingSet[] allExistingSets = manager.getWorkingSets();
IWorkingSet workingSet = null;
// The prints information about all working sets.
for (IWorkingSet myset : allExistingSets) {
workingSet = myset;
IAdaptable[] elems = myset.getElements();
System.out.println("Working set " + myset.getName() + " has "
+ elems.length + " projects.");
for (IAdaptable elem : elems) {
System.out.println("Working set " + myset.getName()
+ " contains " + elem.toString());
}
}
page.setWorkingSets(allExistingSets);
NavigatorActionService actionService = projExplorer
.getNavigatorActionService();
CommonViewer viewer = (CommonViewer) projExplorer
.getAdapter(CommonViewer.class);
INavigatorContentService contentService = viewer
.getNavigatorContentService();
try {
IExtensionStateModel extensionStateModel = contentService
.findStateModel(WorkingSetsContentProvider.EXTENSION_ID);
extensionStateModel.setBooleanProperty(
WorkingSetsContentProvider.SHOW_TOP_LEVEL_WORKING_SETS,
true);
projExplorer.setRootMode(ProjectExplorer.WORKING_SETS);
WorkingSetActionProvider provider = (WorkingSetActionProvider) getActionProvider(
contentService, actionService,
WorkingSetActionProvider.class);
IPropertyChangeListener l = provider.getFilterChangeListener();
PropertyChangeEvent pevent = new PropertyChangeEvent(this,
WorkingSetFilterActionGroup.CHANGE_WORKING_SET, null,
page.getAggregateWorkingSet());
l.propertyChange(pevent);
viewer.refresh();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static CommonActionProvider getActionProvider(
INavigatorContentService contentService,
NavigatorActionService actionService, Class cls) throws Exception {
CommonActionProvider provider = null;
CommonActionProviderDescriptor[] providerDescriptors = CommonActionDescriptorManager
.getInstance().findRelevantActionDescriptors(contentService,
new ActionContext(new StructuredSelection()));
if (providerDescriptors.length > 0) {
for (int i = 0; i < providerDescriptors.length; i++) {
provider = actionService
.getActionProviderInstance(providerDescriptors[i]);
if (provider.getClass() == cls)
return provider;
}
}
return null;
}
It doesn't reset the radio button in the view menu for Top Level Elements though. It also has to use internals to work.
After setting the new working sets into the active page. Did you change your project explorer view into working sets mode?
Please find the project explorer view and do set the mode.
ProjectExplorer projExplorer = (ProjectExplorer) page.findView(IPageLayout.ID_PROJECT_EXPLORER);
projExplorer.setRootMode(ProjectExplorer.WORKING_SETS);
I have a plug-in and want to detect when projects are added to workspace, to set some project settings from my plug-in code, Any Ideas.
Specially i want to call setHidden in some resources that are derived files, as this settings seems to not be part of the project, i mean whenever a resources is hidden seems to not persist if i import the project in a new workspace.
Ironically, I just wrote something like this yesterday. It is a bit more complicated than you would like. Here is a code snippet for you to play with:
public class ProjectListener implements IResourceChangeListener {
public void resourceChanged(IResourceChangeEvent event) {
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
List<IProject> projects = getProjects(event.getDelta());
// do something with new projects
}
}
private List<IProject> getProjects(IResourceDelta delta) {
final List<IProject> projects = new ArrayList<IProject>();
try {
delta.accept(new IResourceDeltaVisitor() {
public boolean visit(IResourceDelta delta) throws CoreException {
if (delta.getKind() == IResourceDelta.ADDED &&
delta.getResource().getType() == IResource.PROJECT) {
IProject project = (IProject) delta.getResource();
if (project.isAccessible()) {
projects.add(project);
}
}
// only continue for the workspace root
return delta.getResource().getType() == IResource.ROOT;
}
});
} catch (CoreException e) {
// handle error
}
return projects;
}
Then, you need to add this ProjectListener to the Workspace, preferably in the start method of your plugin activator:
ResourcesPlugin.getWorkspace().addResourceChangeListener(ProjectListener.LISTENER, IResourceChangeEvent.POST_CHANGE);
And then you want to remove it in the stop method. I literally just wrote this code yesterday. I hope it helps.
You can define a resourcelistener to the workspace, and look for changes in the resource root. See the following article for details: http://www.eclipse.org/articles/Article-Resource-deltas/resource-deltas.html
I am new to Selenium and just started to use it. I want to open a new browser session in a different window from my script and do not know how to do it.
I tried using the open command and gave the Firefox Url but it opened in the same window.
Any ideas?
Try using openWindow instead of open. If you get a message that Firefox blocked a popup, allow popups. This will probably open a tab instead of a window, but maybe that will suit your needs.
#Test
public void Test01() throws Exception {
openTab("http://www.xyz.com");
}
This will open a different Firefox window. And then Handle to switch the new window.
public void trigger(String script, WebElement element) {
((JavascriptExecutor) driver).executeScript(script, element);
}
public Object trigger(String script) {
return ((JavascriptExecutor) driver).executeScript(script);
}
public void openTab(String url) {
String script = "var d=document,a=d.createElement('a');a.target='_blank';a.href='%s';a.innerHTML='.';d.body.appendChild(a);return a";
Object element = trigger(String.format(script, url));
if (element instanceof WebElement) {
WebElement anchor = (WebElement) element;
anchor.click();
trigger("var a=arguments[0];a.parentNode.removeChild(a);", anchor);
} else {
throw new JavaScriptException(element, "Unable to open Window", 1);
}
}