public CloseOperationState canCloseElement() { // if this is not the last cloned xml editor component, closing is OK if (!mDataObject.getEditorSupport().isModified() || !CasaDataEditorSupport.isLastView(multiViewObserver.getTopComponent())) { return CloseOperationState.STATE_OK; } AbstractAction save = new AbstractAction() { public void actionPerformed(ActionEvent arg0) { // save changes try { mDataObject.getEditorSupport().saveDocument(); mDataObject.setModified(false); } catch (IOException ex) { } } }; save.putValue( Action.LONG_DESCRIPTION, NbBundle.getMessage( DataObject.class, "MSG_SaveFile", // NOI18N mDataObject.getPrimaryFile().getNameExt())); return MultiViewFactory.createUnsafeCloseState( "ID_CASA_CLOSING", // NOI18N save, MultiViewFactory.NOOP_CLOSE_ACTION); // return a placeholder state - to be sure our CloseHandler is called /*return MultiViewFactory.createUnsafeCloseState( "ID_TEXT_CLOSING", // dummy ID // NOI18N MultiViewFactory.NOOP_CLOSE_ACTION, MultiViewFactory.NOOP_CLOSE_ACTION);*/ }
@Override @SuppressWarnings("unchecked") public TopComponent getTopComponent() { // Loading the multiview windows: FileObject multiviewsFolder = FileUtil.getConfigFile("skitmultiviews"); FileObject[] kids = multiviewsFolder.getChildren(); MultiViewDescription[] descriptionArray = new MultiViewDescription[kids.length]; ArrayList<MultiViewDescription> listOfDescs = new ArrayList<MultiViewDescription>(); for (FileObject kid : FileUtil.getOrder(Arrays.asList(kids), true)) { MultiViewDescription attribute = (MultiViewDescription) kid.getAttribute("multiview"); if (attribute instanceof ContextAwareInstance) { Lookup lu = Lookups.fixed(this); attribute = ((ContextAwareInstance<MultiViewDescription>) attribute).createContextAwareInstance(lu); } listOfDescs.add(attribute); } for (int i = 0; i < listOfDescs.size(); i++) { descriptionArray[i] = listOfDescs.get(i); } CloneableTopComponent ctc = MultiViewFactory.createCloneableMultiView(descriptionArray, descriptionArray[0]); return ctc; }