本文整理汇总了Java中org.openide.windows.TopComponent.getLookup方法的典型用法代码示例。如果您正苦于以下问题:Java TopComponent.getLookup方法的具体用法?Java TopComponent.getLookup怎么用?Java TopComponent.getLookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.windows.TopComponent
的用法示例。
在下文中一共展示了TopComponent.getLookup方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
/** Setup component with lookup.
*/
@Override
protected void setUp () {
final MVElemTopComponent elem1 = new MVElemTopComponent();
final MVElemTopComponent elem2 = new MVElemTopComponent();
final MVElemTopComponent elem3 = new MVElemTopComponent();
desc1 = new MVDesc("desc1", null, 0, elem1);
desc2 = new MVDesc("desc2", null, 0, elem2);
desc3 = new MVDesc("desc3", null, 0, elem3);
MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2, desc3 };
TopComponent mvtop = MultiViewFactory.createMultiView(descs, desc1);
top = (TopComponent)elem1;
get = top;
top2 = (TopComponent)elem2;
top3 = (TopComponent)elem3;
lookup = mvtop.getLookup();
mvtop.open();
mvtop.requestActive();
mvtc = mvtop;
}
示例2: propertyChange
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
@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);
}
}
}
示例3: propertyChange
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
@Override
public void propertyChange(PropertyChangeEvent evt) {
if(TopComponent.Registry.PROP_TC_OPENED.equals(evt.getPropertyName())) {
Object obj = evt.getNewValue();
if(obj instanceof TopComponent) {
final TopComponent openedTC = (TopComponent) obj;
Lookup lookup = openedTC.getLookup();
DataObject openedDataObject = lookup.lookup(DataObject.class);
dataObjectFoundInLookup = openedDataObject != null;
// if(openedDataObject != null) {
// dataObjectOnTCOpen = data == openedDataObject;
// }
// else {
// Result<DataObject> r = lookup.lookupResult(DataObject.class);
// r.addLookupListener(new LookupListener() {
// @Override
// public void resultChanged(LookupEvent ev) {
// Lookup lookup = openedTC.getLookup();
// DataObject openedDataObject = lookup.lookup(DataObject.class);
// dataObjectAfterTCOpen = data == openedDataObject;
// }
// });
// }
this.tc = openedTC;
}
opened = true;
}
}
示例4: saveDocuments
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
private void saveDocuments(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveDocuments
// Add your handling code here:
Node[] selNodes = explorer.getSelectedNodes();
if (selNodes.length == 0) {
return;
}
for (int i = 0; i < selNodes.length; i++) {
TopComponent tc = ((TopComponentNode) selNodes[i]).getTopComponent();
Lookup l = tc.getLookup();
SaveCookie sc = (SaveCookie) l.lookup(SaveCookie.class);
if (sc != null) {
try {
sc.save();
} catch (IOException exc) {
Logger.getAnonymousLogger().log(Level.WARNING,
"[WinSys.DocumentsDlg.saveDocuments]" // NOI18N
+ " Warning: Cannot save content of TopComponent: [" // NOI18N
+ WindowManagerImpl.getInstance().getTopComponentDisplayName(tc) + "]" // NOI18N
+ " [" + tc.getClass().getName() + "]", exc); // NOI18N
}
//Refresh name of node because TopComponent name is probably changed too
//('*' is removed)
((TopComponentNode) selNodes[i]).refresh();
}
}
jButtonSave.setEnabled(false);
}
示例5: handlePopupMenuShowing
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
/** Possibly invokes popup menu. */
public static void handlePopupMenuShowing(MouseEvent e, int idx) {
Component c = (Component) e.getSource();
while (c != null && !(c instanceof Tabbed.Accessor))
c = c.getParent();
if (c == null) {
return;
}
final Tabbed tab = ((Tabbed.Accessor)c).getTabbed();
final Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), c);
final int clickTab = idx;
Lookup context = null;
Action[] actions = null;
if (clickTab >= 0) {
TopComponent tc = tab.getTopComponentAt(clickTab);
if(tc != null) {
// ask also tabbed to possibly alter actions
actions = tab.getPopupActions(tc.getActions(), clickTab);
if (actions == null) {
actions = tc.getActions();
}
if (actions == null || actions.length == 0 )
return;
context = tc.getLookup();
}
}
if( null == context ) {
actions = tab.getPopupActions(new Action[0], -1);
if (actions == null || actions.length == 0 )
return;
context = Lookup.getDefault();
}
showPopupMenu(Utilities.actionsToPopup(actions, context), p, c);
}
示例6: getSaveCookie
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
private static SaveCookie getSaveCookie(TopComponent tc) {
Lookup lookup = tc.getLookup();
Object obj = lookup.lookup(SaveCookie.class);
if(obj instanceof SaveCookie) {
return (SaveCookie)obj;
}
return null;
}
示例7: getLookup
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
/** The current component lookup */
public Lookup getLookup() {
Lookup l = temporary;
if (l != null) {
return l;
}
TopComponent tc = registry.getActivated();
return tc == null ? Lookup.EMPTY : tc.getLookup();
}
示例8: initEditorDocuments
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
private void initEditorDocuments() {
elementsList = new JList() {
@Override
public String getToolTipText(MouseEvent event) {
int index = locationToIndex(event.getPoint());
if (index != -1) {
EditorListElement element = (EditorListElement) elementsList.getModel().getElementAt(index);
return element.fileObject.getPath();
}
return null;
}
};
List<EditorListElement> elements = new ArrayList<EditorListElement>();
WindowManager wm = WindowManager.getDefault();
Set<? extends Mode> modes = wm.getModes();
for (Mode mode : modes) {
if (wm.isEditorMode(mode)) {
TopComponent[] tcs = mode.getTopComponents();
for (TopComponent tc : tcs) {
Lookup lukap = tc.getLookup();
FileObject fo = lukap.lookup(FileObject.class);
if (fo == null) {
DataObject dobj = lukap.lookup(DataObject.class);
if (dobj != null) {
fo = dobj.getPrimaryFile();
}
}
if (fo != null && fo != peer) {
if (tc.getHtmlDisplayName() != null) {
elements.add(new EditorListElement(fo, tc.getHtmlDisplayName(), true));
} else {
elements.add(new EditorListElement(fo, tc.getName(), false));
}
}
}
}
}
elementsList.setListData(elements.toArray(new EditorListElement[elements.size()]));
elementsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
elementsList.addListSelectionListener(this);
elementsList.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (isSelected && value instanceof EditorListElement && ((EditorListElement) value).isHtml()) {
value = stripHtml(((EditorListElement) value).toString());
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
private String stripHtml (String htmlText) {
if (null == htmlText) {
return null;
}
String res = htmlText.replaceAll("<[^>]*>", ""); // NOI18N // NOI18N
res = res.replaceAll(" ", " "); // NOI18N // NOI18N
res = res.trim();
return res;
}
});
JScrollPane sp = new JScrollPane(elementsList);
jPanel1.add(sp);
}
示例9: setUp
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
/** Setup component with lookup.
*/
protected void setUp () {
top = new TopComponent ();
get = top;
lookup = top.getLookup ();
}
示例10: performAction
import org.openide.windows.TopComponent; //导入方法依赖的package包/类
@Override
protected void performAction(final Node[] activatedNodes) {
VCSContext ctx = VCSContext.forNodes(activatedNodes);
final Set<VCSFileProxy> rootSet = ctx.getRootFiles();
final VCSFileProxy[] files = rootSet.toArray(new VCSFileProxy[rootSet.size()]);
if(!files[0].isFile()) {
return;
}
VCSFileProxy file = files[0];
FileObject fo = file.toFileObject();
if(fo != null) {
DataObject dataObject = null;
try {
dataObject = DataObject.find(fo);
} catch (DataObjectNotFoundException ex) {
History.LOG.log(Level.WARNING, null, ex);
}
if(dataObject != null) {
if(!hasHistoryElement(dataObject)) {
// there is no history element defined for this data object, so
// lets open in a separate TopComponent
openLocalHistoryTC(files);
return;
}
// activate the History tab if there is a opened TopComponent
// with a History MultiView element
Set<TopComponent> tcs = TopComponent.getRegistry().getOpened();
for (final TopComponent tc : tcs) {
Lookup l = tc.getLookup();
final DataObject tcDataObject = l.lookup(DataObject.class);
if (tcDataObject != null && dataObject.equals(tcDataObject)) {
final MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
if(handler != null) {
if(activateHistoryTab(handler, tc)) {
// done, history tab found and activated.
return;
}
}
}
}
final EditorCookie editorCookie = dataObject.getLookup().lookup(EditorCookie.class);
if(editorCookie != null) {
Runnable r = new Runnable() {
@Override
public void run() {
JEditorPane pane = NbDocument.findRecentEditorPane(editorCookie);
if(pane != null) {
// editor is oen, though we havent found a multiview => open the LH top component
openLocalHistoryTC(files);
}
}
};
if(SwingUtilities.isEventDispatchThread()) {
r.run();
} else {
SwingUtilities.invokeLater(r);
}
}
EditCookie editCookie = dataObject.getLookup().lookup(EditCookie.class);
if(editCookie != null) {
// no editor found, lets open it...
// editcookie might return imediately, so listen for the TC
// to be opened and activate then
TopComponent.getRegistry().addPropertyChangeListener(new TCOpenedListener(dataObject, files));
editCookie.edit();
return;
}
}
}
openLocalHistoryTC(files);
}