Java Code Examples for org.openide.windows.TopComponent#close()

The following examples show how to use org.openide.windows.TopComponent#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DesignView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    BIG: for (Mode m : WindowManager.getDefault().getModes()) {
        boolean found = false;
        for (TopComponent topComponent : m.getTopComponents()) {
            if (topComponent instanceof DesignViewComponent) {
                found = true;
                continue;
            }
            topComponent.close();
        }
        if (!found) {
            final DesignViewComponent mc = new DesignViewComponent();
            m.dockInto(mc);
            mc.open();
        }
    }
}
 
Example 2
Source File: ShowHistoryAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if(Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) {
        try {
            TopComponent tc =(TopComponent) evt.getNewValue();
            Lookup l = tc.getLookup();
            DataObject tcDataObject = l.lookup(DataObject.class);
            
            if (tcDataObject != null && dataObject.equals(tcDataObject)) {
                final MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
                if (handler == null || !activateHistoryTab(handler, tc)) {
                    // oops, whats this? 
                    // lets fallback on LHTC
                    tc.close();
                    openLocalHistoryTC(files);
                }
            }
        } finally {
            TopComponent.getRegistry().removePropertyChangeListener(this);
        }
    }
}
 
Example 3
Source File: TopComponentCreationTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test saving of TopComponent with persistence type
 * TopComponent.PERSISTENCE_NEVER.
 */
public void testSavePersistentNeverTopComponent () throws Exception {
    WindowManager wm = WindowManager.getDefault();
    
    Mode m = wm.findMode("explorer");
    assertNotNull("Mode explorer must be present", m);
    
    TopComponent tc = new Component02();
    m.dockInto(tc);
    tc.open();
    
    String res = "Windows2Local/Modes/explorer/"
    + wm.findTopComponentID(tc) + ".wstcref";
    
    //Check that non persistent, opened TC is NOT saved ie. wstcref file is NOT created
    PersistenceHandler.getDefault().save();
    //Check wstcref file was not created
    assertNull(FileUtil.getConfigFile(res));
    deleteLocalData();
    
    //Check that non persistent, closed TC is NOT saved ie. wstcref file is NOT created
    tc.close();
    PersistenceHandler.getDefault().save();        
    //Check wstcref file was not created
    assertNull(FileUtil.getConfigFile(res));
    deleteLocalData();
}
 
Example 4
Source File: EditDBNodeAction.java    From BART with MIT License 5 votes vote down vote up
public static void closeDBTopComponent(String name)   {
    Set<TopComponent> set = WindowManager.getDefault().getRegistry().getOpened();
    Iterator<TopComponent> it = set.iterator();
    while(it.hasNext())   {
        TopComponent tmp = it.next();
        if(tmp.getName().equals(name))   {
            tmp.close();
            break;
        }
    } 
}
 
Example 5
Source File: EGTaskDataObjectDataObject.java    From BART with MIT License 5 votes vote down vote up
@Override
public boolean close() {
    if(isEgtModified())   {
        Object result =DialogDisplayer.getDefault().notify(
                        new NotifyDescriptor.Confirmation(
                        Bundle.MSG_EGTaskDataObject_Close(this.getPrimaryFile().getName()),
                        "Save", 
                        NotifyDescriptor.YES_NO_OPTION)
        );
        if(result.equals(NotifyDescriptor.YES_OPTION))   {
            for(TopComponent tc : WindowManager.getDefault().getRegistry().getOpened())   {
                if(tc.getDisplayName().equals(this.getPrimaryFile().getName()))   {
                    tc.close();
                }         
            }
            try{
                abstractLookup.lookup(Savable.class).save();
            }catch(IOException ioe)   {
                ErrorManager.getDefault().notify(ErrorManager.ERROR, ioe);
                return false;
            }
        }
    }
    resetContent();
    closeEditorTopComponet();
    this.setEgtModified(false);
    this.setEGTask(null);
    RootNodeNotifier.fire();
    CentralLookup.getDefLookup().clean();
    return true;
}
 
Example 6
Source File: EGTaskDataObjectDataObject.java    From BART with MIT License 5 votes vote down vote up
private void closeEditorTopComponet()   {
    for(TopComponent tc : WindowManager.getDefault().getRegistry().getOpened())   {
        if(WindowManager.getDefault().isEditorTopComponent(tc))   {
            tc.close();
        }         
    } 
}
 
Example 7
Source File: UtilTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreateIssue() {
    Repository repo = getRepo();
    APITestRepository apiRepo = getApiRepo();
    
    apiRepo.newIssue = null;
    String summary = "summary";
    String desc = "desc";
    Util.createIssue(repo, summary, desc);
    
    long t = System.currentTimeMillis();
    TopComponent openedTC = null;
    while(openedTC == null) {
        Set<TopComponent> openedTCs = WindowManager.getDefault().getRegistry().getOpened();
        for (TopComponent tc : openedTCs) {
            if(tc instanceof IssueTopComponent) {
                IssueTopComponent itc = (IssueTopComponent)tc;
                IssueImpl issueImpl = itc.getIssue();
                if(issueImpl != null && issueImpl.isData(apiRepo.newIssue)) {
                    openedTC = tc;
                    break;
                }
            }
        }
        if(System.currentTimeMillis() - t > 5000) {
            break;
        }
    }
    
    assertNotNull(apiRepo.newIssue);
    if(openedTC == null) {
        fail("TopComponent with new issue wasn't opened");
    }
    assertEquals(summary, apiRepo.newIssue.getSummary());
    assertEquals(desc, apiRepo.newIssue.getDescription());
    
    openedTC.close();
}
 
Example 8
Source File: UtilTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreateNewIssue() {
    Repository repo = getRepo();
    APITestRepository apiRepo = getApiRepo();
    
    apiRepo.newIssue = null;
    Util.createNewIssue(repo);
    
    long t = System.currentTimeMillis();
    TopComponent openedTC = null;
    while(openedTC == null) {
        Set<TopComponent> openedTCs = WindowManager.getDefault().getRegistry().getOpened();
        for (TopComponent tc : openedTCs) {
            if(tc instanceof IssueTopComponent) {
                IssueTopComponent itc = (IssueTopComponent)tc;
                IssueImpl issueImpl = itc.getIssue();
                if(issueImpl != null && issueImpl.isData(apiRepo.newIssue)) {
                    openedTC = tc;
                    break;
                }
            }
        }
        if(System.currentTimeMillis() - t > 5000) {
            break;
        }
    }
    
    assertNotNull(apiRepo.newIssue);
    if(openedTC == null) {
        fail("TopComponent with new issue wasn't opened");
    }
    openedTC.close();
}
 
Example 9
Source File: TopComponentListener.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
public void register(TopComponent slaveComponent, String masterComponentName) {
    this.tc = slaveComponent;
    this.mainComponent = masterComponentName;
    TopComponent.getRegistry().addPropertyChangeListener(this);
    TopComponent main = view.findWindowByName(masterComponentName);
    if (main == null || !main.isOpened()) {
        slaveComponent.close();
    }
}
 
Example 10
Source File: TopComponentCreationTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test saving of TopComponent with persistence type
 * TopComponent.PERSISTENCE_ONLY_OPENED.
 */
public void testSavePersistentOnlyOpenedTopComponent () throws Exception {
    WindowManager wm = WindowManager.getDefault();
    
    Mode m = wm.findMode("explorer");
    assertNotNull("Mode explorer must be present", m);
    
    TopComponent tc = new Component01();
    m.dockInto(tc);
    tc.open();
    
    String res = "Windows2Local/Modes/explorer/"
    + wm.findTopComponentID(tc) + ".wstcref";
    
    //Check that persistent only opened, opened TC is saved ie. wstcref file is created
    PersistenceHandler.getDefault().save();
    //Check wstcref file was created
    assertNotNull(FileUtil.getConfigFile(res));
    deleteLocalData();
    //Check wstcref file was deleted
    assertNull(FileUtil.getConfigFile(res));
    
    //Check that persistent only opened, closed TC is NOT saved ie. wstcref file is NOT created
    tc.close();
    PersistenceHandler.getDefault().save();        
    //Check wstcref file was not created
    assertNull(FileUtil.getConfigFile(res));
    deleteLocalData();
}
 
Example 11
Source File: TopComponentCreationTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test saving of TopComponent with persistence type
 * TopComponent.PERSISTENCE_ALWAYS.
 */
public void testSavePersistentTopComponent () throws Exception {
    WindowManager wm = WindowManager.getDefault();
    
    Mode m = wm.findMode("explorer");
    assertNotNull("Mode explorer must be present", m);
    
    TopComponent tc = Component00.getDefault();
    m.dockInto(tc);
    tc.open();
    
    String res = "Windows2Local/Modes/explorer/"
    + wm.findTopComponentID(tc) + ".wstcref";
    //Check that persistent, opened TC is saved ie. wstcref file is created
    PersistenceHandler.getDefault().save();
    //Check wstcref file was created
    assertNotNull(FileUtil.getConfigFile(res));
    deleteLocalData();
    //Check wstcref file was deleted
    assertNull(FileUtil.getConfigFile(res));
    
    //Check that persistent, closed TC is saved ie. wstcref file is created
    tc.close();
    PersistenceHandler.getDefault().save();        
    //Check wstcref file was created
    assertNotNull(FileUtil.getConfigFile(res));
    deleteLocalData();
    //Check wstcref file was deleted
    assertNull(FileUtil.getConfigFile(res));
}
 
Example 12
Source File: DesignView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (TopComponent.Registry.PROP_OPENED.equals(evt.getPropertyName())) {
        for (Mode m : WindowManager.getDefault().getModes()) {
            for (TopComponent topComponent : m.getTopComponents()) {
                if (topComponent instanceof DesignViewComponent) {
                    continue;
                }
                topComponent.close();
            }
        }
    }
}
 
Example 13
Source File: GroupsManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static boolean closeAllDocuments() {
    TopComponent[] tcs = WindowManagerImpl.getInstance().getEditorTopComponents();
    for( TopComponent tc : tcs ) {
        if( !Switches.isClosingEnabled(tc) ) {
            continue;
        }
        tc.putClientProperty("inCloseAll", Boolean.TRUE); //NOI18N
        if( !tc.close() ) {
            return false;
        }
    }

    return true;
}
 
Example 14
Source File: SlideBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void userMiddleClickedSlidingButton(Component clickedButton) {
    int index = getButtonIndex(clickedButton);
    SlidingButton button = (SlidingButton) buttons.get(index);
    button.setBlinking(false);
    
    if (index >= 0 && index < dataModel.size() ) {
        TopComponent tc = (TopComponent)dataModel.getTab(index).getComponent();
        tc.close();
    }
}
 
Example 15
Source File: ScreenshotComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void componentHidden() {
    super.componentHidden();
    if (propertiesOpened) {
        propertiesOpened = false;
        TopComponent properties = WindowManager.getDefault().findTopComponent("properties");    // NOI18N
        if (properties != null) {
            properties.close();
        }
    }
}
 
Example 16
Source File: VariablesViewButtons.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void closeView (String viewName) {
    TopComponent view = WindowManager.getDefault().findTopComponent(viewName);
    view.close();
}
 
Example 17
Source File: ModeActivationTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Test basic behavior when Mode is activated. TC is docked into Mode, opened, activated,
 * closed. During this activation state of Mode is tested.
 */
public void testActivate () throws Exception {
    Lookup.getDefault().lookup(ModuleInfo.class);
    
    PersistenceHandler.getDefault().load();
    
    //This must be unit test as we need minimum winsys config
    //if default minimum winsys config is changed this test must be changed too.
    WindowManagerImpl wmi = WindowManagerImpl.getInstance();
    Mode activeMode = wmi.getActiveMode();
    assertNull("No mode is activated ie. active mode must be null",activeMode);
    
    //Mode cannot be activated when it is empty
    Mode editor = wmi.getDefaultEditorMode();
    wmi.setActiveMode((ModeImpl) editor);
    activeMode = wmi.getActiveMode();
    assertNull("Ignore mode activation when mode is empty",activeMode);
    
    //Editor mode must be empty
    TopComponent [] tcs = editor.getTopComponents();
    assertEquals("Mode editor must be empty",tcs.length,0);

    //Dock TC into mode
    TopComponent tc = new TopComponent();
    
    //As tc is not yet docked into any mode this must return null
    Mode m = wmi.findMode(tc);
    assertNull("No mode for TC",m);
    
    editor.dockInto(tc);
    //Editor mode must contain one TC
    tcs = editor.getTopComponents();
    assertEquals("Mode editor must contain one TC", 1, tcs.length);
    
    //Mode cannot be activated when it does not contain opened TC
    wmi.setActiveMode((ModeImpl) editor);
    activeMode = wmi.getActiveMode();
    assertNull("Mode cannot be activated when it does not contain opened TC",activeMode);
    
    m = wmi.findMode(tc);
    assertEquals("Mode editor must be found for TC", editor, m);
    
    //TC is closed
    assertFalse("TC is closed",tc.isOpened());
    
    tc.open();
    //TC is opened
    assertTrue("TC is opened",tc.isOpened());
    tc.requestActive();
    
    //Editor mode is now activated
    activeMode = wmi.getActiveMode();
    assertEquals("Editor mode is now activated",editor,activeMode);
    
    //Check active tc
    TopComponent activeTC = wmi.getRegistry().getActivated();
    assertEquals("TC is now active",tc,activeTC);
    
    tc.close();
    //TC is closed
    assertFalse("TC is closed",tc.isOpened());
    
    //No mode is now activated
    activeMode = wmi.getActiveMode();
    assertNull("No mode is activated ie. active mode must be null", activeMode);
}
 
Example 18
Source File: LoadEGTask.java    From BART with MIT License 4 votes vote down vote up
@Override
    public void load(FileObject file) {

        log.fine("Close EGTaskDataObjectDataObject");
        EGTaskDataObjectDataObject oldDto = CentralLookup.getDefLookup().lookup(EGTaskDataObjectDataObject.class);
        if ((oldDto != null) && (!oldDto.close())) return;

        log.fine("Close TopComponents");
        for (TopComponent tc : WindowManager.getDefault().getRegistry().getOpened()) {
            if (WindowManager.getDefault().isEditorTopComponent(tc)) {
                tc.close();
            }
        }

        try {
            log.fine("Find DataObject for a file");
            egtDO = DataObject.find(file);
        } catch (DataObjectNotFoundException donf) {
            ErrorManager.getDefault().notify(ErrorManager.ERROR, donf);
            StatusBar.setStatus(Bundle.MSG_STATUS_ConfNotLoaded(), 10, 3000);
            log.log(Level.SEVERE, "DataObject notFound", donf);
            return;
        }

        final Dialog d = BusyDialog.getBusyDialog();
        RequestProcessor.Task T = RequestProcessor.getDefault().post(new LoadEGTaskRunnable());
        T.addTaskListener(new TaskListener() {

            @Override
            public void taskFinished(Task task) {
//                d.setVisible(false);
                if (esito) {
                    log.fine("Esito true -> Dataobject to CentralLookup");
                    RootNodeNotifier.fire();
                    CentralLookup.getDefLookup().add(egtDO);
                    log.fine("Set Node Statistic");
                    CentralLookup.getDefLookup().add(new RootNodeStatistic(Children.create(new StatisticNodeFactory(), true)));
                    StatusBar.setStatus(Bundle.MSG_STATUS_ConfLoaded(), 10, 3000);
                } else {
                    log.fine("Esito false -> ");
                    RootNodeNotifier.fire();
                    CentralLookup.getDefLookup().add(egtDO);
                    egtDO.getLookup().lookup(OpenCookie.class).open();
                    StatusBar.setStatus(Bundle.MSG_STATUS_ConfLoadError(), 10, 3000);
                }
//                d.setVisible(false);
            }
        });
//        d.setVisible(true);
    }
 
Example 19
Source File: ActionUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void closeWindow(TopComponent tc) {
    tc.close();
}
 
Example 20
Source File: DefaultActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testListView () {
    TopComponent tc = prepareExplorerPanel (new ListView ());
    invokeDefaultAction (tc);
    assertDefaultActionWasPerformed ("ListView");
    tc.close ();
}