Java源码示例:org.netbeans.core.spi.multiview.CloseOperationState
示例1
public void testCreateUnsafeCloseState () throws Exception {
CloseOperationState state = MultiViewFactory.createUnsafeCloseState("ID_UNSAFE",
MultiViewFactory.NOOP_CLOSE_ACTION, MultiViewFactory.NOOP_CLOSE_ACTION);
assertNotNull(state);
assertFalse(state.canClose());
assertNotNull(state.getDiscardAction());
assertNotNull(state.getProceedAction());
assertEquals("ID_UNSAFE", state.getCloseWarningID());
state = MultiViewFactory.createUnsafeCloseState( null, null, null);
assertNotNull(state);
assertFalse(state.canClose());
assertNotNull(state.getDiscardAction());
assertNotNull(state.getProceedAction());
assertNotNull(state.getCloseWarningID());
}
示例2
public CloseOperationState canCloseElement() {
// if this is not the last cloned editor component, closing is OK
if(!getEditorSupport().isModified() ||
MultiViewSupport.getNumberOfClones(multiViewCallback.getTopComponent()) > 1) {
return CloseOperationState.STATE_OK;
}
// return a state which will save/discard changes and is called by close handler
AbstractAction save = new AbstractAction(){
public void actionPerformed(ActionEvent arg0) {
//save changes
try {
getEditorSupport().saveDocument();
} catch (IOException ex) {
}
}
};
save.putValue(Action.LONG_DESCRIPTION, NbBundle.getMessage(DataObject.class,
"MSG_SaveFile", // NOI18N
getEditorSupport().getDataObject().getPrimaryFile().getNameExt()));
return MultiViewFactory.createUnsafeCloseState(
"ID_JAXWS_CLOSING", // NOI18N
save,
MultiViewFactory.NOOP_CLOSE_ACTION);
}
示例3
@Override
public CloseOperationState canCloseElement() {
if (dObj == null || dObj.canClose()) {
return CloseOperationState.STATE_OK;
} else if (!this.callback.isSelectedElement()) {
return CloseOperationState.STATE_OK;
} else if (!dObj.isModified()) {
return CloseOperationState.STATE_OK;
} else {
boolean differ = false;
String message = dObj.getEditorSupport().messageSave();
try {
String encoding = dObj.encoding();
differ = dObj.encodingDiffer(encoding);
if (differ) {
message += " <b>" + dObj.encodingMessage(encoding) + "</b>";
}
} catch (IOException ex) {
LOGGER.log(Level.INFO, null, ex);
}
message = "<html>" + message + "</html>";
return MultiViewFactory.createUnsafeCloseState(
message, new SaveAction(differ), new DiscardAction());
}
}
示例4
final CloseOperationState canCloseElement(TopComponent tc) {
// if this is not the last cloned java editor component, closing is OK
if (!isLastView(tc)) {
return CloseOperationState.STATE_OK;
}
if (!isModified()) {
return CloseOperationState.STATE_OK;
}
AbstractAction save = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
saveDocument();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
};
save.putValue(Action.LONG_DESCRIPTION, NbBundle.getMessage(BIEditorSupport.class, "MSG_MODIFIED", getDataObject().getPrimaryFile().getNameExt()));
// return a placeholder state - to be sure our CloseHandler is called
return MultiViewFactory.createUnsafeCloseState(
"ID_BEANINFO_CLOSING", // NOI18N
save,
MultiViewFactory.NOOP_CLOSE_ACTION);
}
示例5
@Messages({
"MSG_MODIFIED=File {0} is modified. Save?"
})
final CloseOperationState canCloseElement(TopComponent tc) {
// if this is not the last cloned java editor component, closing is OK
if (!FormEditorSupport.isLastView(tc)) {
return CloseOperationState.STATE_OK;
}
if (!isModified()) {
return CloseOperationState.STATE_OK;
}
AbstractAction save = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
saveDocument();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
};
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_MODIFIED(
getDataObject().getPrimaryFile().getNameExt()
));
// return a placeholder state - to be sure our CloseHandler is called
return MultiViewFactory.createUnsafeCloseState(
"ID_FORM_CLOSING", // NOI18N
save,
MultiViewFactory.NOOP_CLOSE_ACTION);
}
示例6
@Override
public CloseOperationState canCloseElement() {
if (javaEditor == null) {
return CloseOperationState.STATE_OK;
}
return javaEditor.canCloseElement(multiViewObserver.getTopComponent());
}
示例7
public boolean resolveCloseOperation(CloseOperationState[] elements) {
wasUsed = true;
if (supposed != elements.length) {
throw new IllegalStateException("A different number of elements returned. Expected=" + supposed + " but was:" + elements.length);
}
return canClose;
}
示例8
@Override
public boolean resolveCloseOperation(CloseOperationState[] elements) {
assertNull("globalElement not specified yet", globalElements);
assertNotNull("We know what to return", retValue);
boolean r = retValue;
retValue = null;
globalElements = elements;
return r;
}
示例9
@Override
public CloseOperationState canCloseElement() {
if (closeState != null) {
return closeState;
}
return CloseOperationState.STATE_OK;
}
示例10
@Override
public CloseOperationState canCloseElement() {
if (closeState != null) {
return closeState;
}
return CloseOperationState.STATE_OK;
}
示例11
@Override
public CloseOperationState canCloseElement() {
if (!getEditorSupport().isModified()) {
return CloseOperationState.STATE_OK;
}
AbstractAction save = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent arg0) {
//save changes
try {
getEditorSupport().saveDocument();
} catch (IOException ex) {
LOG.log(Level.WARNING, "File {0} couldn''t be saved.", context.getFacesConfigFile().getName());
}
}
};
save.putValue(Action.LONG_DESCRIPTION, NbBundle.getMessage(DataObject.class,
"MSG_SaveFile", // NOI18N
getEditorSupport().getDataObject().getPrimaryFile().getNameExt()));
return MultiViewFactory.createUnsafeCloseState(
"ID_FACES_CONFIG_CLOSING", //NOI18N
save,
MultiViewFactory.NOOP_CLOSE_ACTION);
}
示例12
public CloseOperationState canCloseElement() {
try {
editor.fireVetoableChange(TreePanelDesignEditor.PROPERTY_FLUSH_DATA, this, null);
} catch (PropertyVetoException e) {
return MultiViewFactory.createUnsafeCloseState(TreePanelDesignEditor.PROPERTY_FLUSH_DATA, null, null);
}
return super.canCloseElement();
}
示例13
public CloseOperationState canCloseElement() {
if (!editorValidate()) {
return MultiViewFactory.createUnsafeCloseState(ToolBarDesignEditor.PROPERTY_FLUSH_DATA, null, null);
} else {
return super.canCloseElement();
}
}
示例14
@Messages({
"MSG_SaveModified=File {0} is modified. Save?"
})
@Override
public CloseOperationState canCloseElement() {
final CloneableEditorSupport sup = getLookup().lookup(CloneableEditorSupport.class);
Enumeration en = getReference().getComponents();
if (en.hasMoreElements()) {
en.nextElement();
if (en.hasMoreElements()) {
// at least two is OK
return CloseOperationState.STATE_OK;
}
}
PropertiesDataObject dataObject = getDataObject();
if (dataObject.isModified()) {
AbstractAction save = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
sup.saveDocument();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
};
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(FileUtil.getFileDisplayName(dataObject.getPrimaryFile())));
return MultiViewFactory.createUnsafeCloseState("editor", save, null);
}
return CloseOperationState.STATE_OK;
}
示例15
@Messages({
"MSG_SaveModified=File {0} is modified. Save?"
})
@Override
public CloseOperationState canCloseElement() {
if (sqlEditorSupport().isConsole()) {
return CloseOperationState.STATE_OK;
} else {
DataObject sqlDO = sqlEditorSupport().getDataObject();
FileObject sqlFO = sqlEditorSupport().getDataObject().getPrimaryFile();
if (sqlDO.isModified()) {
if (sqlFO.canWrite()) {
Savable sav = sqlDO.getLookup().lookup(Savable.class);
if (sav != null) {
AbstractAction save = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
sqlEditorSupport().saveDocument();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
};
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(sqlFO.getNameExt()));
return MultiViewFactory.createUnsafeCloseState("editor", save, null);
}
}
}
}
return CloseOperationState.STATE_OK;
}
示例16
@Override
public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例17
@Override
public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例18
@Override
public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例19
@Override public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例20
@Override public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例21
@Override public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例22
@Override
public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例23
public CloseOperationState canCloseElement() {
DataObject dataObject = callback.getTopComponent().getLookup().lookup(DataObject.class);
BIEditorSupport editor = (BIEditorSupport) cloneableEditorSupport();
return editor.canCloseElement(callback.getTopComponent());
}
示例24
@Override
public CloseOperationState canCloseElement() {
BIEditorSupport editor = findEditor(dataObject);
return editor.canCloseElement(callback.getTopComponent());
}
示例25
@Override
public CloseOperationState canCloseElement() {
return formEditorSupport.canCloseElement(multiViewObserver.getTopComponent());
}
示例26
@Override
public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;
}
示例27
@Override
public CloseOperationState canCloseElement() {
return editor.canCloseElement();
}
示例28
@Messages({
"# {0} - file name", "MSG_SaveModified=File {0} is modified. Save?",
"MSG_SaveModified_no_name=File is modified. Save?"
})
@Override
public CloseOperationState canCloseElement() {
final CloneableEditorSupport sup = getLookup().lookup(CloneableEditorSupport.class);
Enumeration<CloneableTopComponent> en = getReference().getComponents();
if (en.hasMoreElements()) {
en.nextElement();
if (en.hasMoreElements()) {
// at least two is OK
return CloseOperationState.STATE_OK;
}
}
Savable sav = getLookup().lookup(Savable.class);
if (sav != null) {
AbstractAction save = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
sup.saveDocument();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
};
try {
if (sav.getClass().getMethod("toString").getDeclaringClass() != Object.class) {
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(sav));
} else {
Logger.getLogger(MultiViewCloneableEditor.class.getName()).log(Level.WARNING,
"Need to override toString() to contain the file name in o.n.api.action.Savable {0} with lookup {1}",
new Object[] {sav.getClass(), getLookup().lookupAll(Object.class)});
Node n = getLookup().lookup(Node.class);
if (n != null) {
// #201696: compatibility fallback.
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(n.getDisplayName()));
} else {
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified_no_name());
}
}
} catch (NoSuchMethodException x) {
assert false : x;
}
return MultiViewFactory.createUnsafeCloseState("editor", save, null);
}
return CloseOperationState.STATE_OK;
}
示例29
public boolean resolveCloseOperation(CloseOperationState[] elements) {
wasUsed = true;
return canClose;
}
示例30
public CloseOperationState canCloseElement() {
return MultiViewFactory.createUnsafeCloseState("ID", MultiViewFactory.NOOP_CLOSE_ACTION, MultiViewFactory.NOOP_CLOSE_ACTION);
}